繁体   English   中英

本地通知

[英]Local Notification

我在游戏应用中实施了本地通知,每天都会触发一次,以获取每日奖金。 当我点击通知横幅时,一切正常,但是,当我从应用程序图标进入该应用程序时,本地通知无法正常运行。

这是我的代码:

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

我将不胜感激任何帮助。

这就是它的工作方式。
从图标启动应用程序不会触发任何通知,仅会从横幅通知您。
如果您想要即使用户没有点击横幅就奖励他们,也应该使用与触发通知的逻辑相同的逻辑-只需计算距该应用程序上次运行以来已经花了多长时间并在那里进行操作。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM