本地通知
我在我的游戏应用程序中实施了一个本地通知,每天发一次每日奖金。 当我点击通知横幅时,这一切正常,但是,当我从应用程序图标进入应用程序,本地通知不应该像它应该。
这是我的代码:
-(BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary*)launchOptions{ ....... ....... application.applicationIconBadgeNumber = 0; UILocalNotification *localNotif = [launchOptions objectForKey:UIApplicationLaunchOptionsLocalNotificationKey]; if (localNotif) { NSLog(@"recieved notification %@",localNotif); UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"Daily Bonus" message:@"You recieved 100 free coins" delegate:nil cancelButtonTitle:nil otherButtonTitles:@"ok", nil]; [alert show]; [alert release]; NSUserDefaults *standardUserDefaults = [NSUserDefaults standardUserDefaults]; float balance = [standardUserDefaults floatForKey:kCurrentScore]; balance +=100.0f; NSLog(@"%g",balance); [standardUserDefaults setFloat:balance forKey:kCurrentScore]; [standardUserDefaults synchronize]; }
我将不胜感激任何帮助。
这是它的工作方式。
从它的图标启动应用程序不会触发任何通知到您的应用程序,只能从横幅。
如果你想奖励你的用户,即使他们没有点击横幅,你也应该使用和触发你的通知一样的逻辑 – 只要计算自从应用程序上次运行到现在已经有多长时间了。
- 访问XCTestCase类中的应用程序委托对象导致misaligned_stack_error_ swift
- 从应用程序委托获取当前的视图控制器(模态是可能的)
- 在swift中configuration深层链接?
- 当App Delegate的方法将终止执行?
- NSInternalInconsistencyException',原因:'无法在捆绑中加载NIB:'NSBundle
- applicationWillEnterForeground提供一个视图控制器
- 从UIViewController更改AppDelegate的属性不起作用
- 我如何连接UITableView到我的Appdelegate.m?
- 如何阻止iOS 7控制中心控制音乐应用程序?