我在我的游戏应用程序中实现了一个本地通知,该通知每天启动一次以获得每日奖励。当我点击通知横幅时一切正常,但是,当我从应用程序图标进入应用程序时,本地通知无法正常工作。
这是我的代码:
-(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];
}
我将不胜感激任何帮助。