Ios 本地通知

Ios 本地通知,ios,uilocalnotification,appdelegate,Ios,Uilocalnotification,Appdelegate,我在我的游戏应用程序中实现了一个本地通知,每天触发一次,获得每日奖金。当我点击通知横幅时一切正常,但是当我从应用程序图标进入应用程序时,本地通知无法正常工作 这是我的密码: -(BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary*)launchOptions{ ....... ....... application.applicationIconBadgeNumber

我在我的游戏应用程序中实现了一个本地通知,每天触发一次,获得每日奖金。当我点击通知横幅时一切正常,但是当我从应用程序图标进入应用程序时,本地通知无法正常工作

这是我的密码:

-(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];
}

非常感谢您的帮助。

这就是它的工作方式。
从图标启动应用程序不会触发任何应用程序通知,仅在横幅上显示。
如果您想奖励用户,即使他们没有点击横幅,您可能应该使用与触发通知相同的逻辑-只需计算应用程序上次运行以来的时间,然后在那里执行您的操作即可