本地通知 [英] Local Notification

查看:31
本文介绍了本地通知的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I implemented a local notification in my game app that fires up once a day for a daily bonus. It all works fine when I tap the notification banner, however, when i get in to the app from the app icon, the local notification doesn't work like it should.

这是我的代码:

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

我将不胜感激.

推荐答案

这就是它的工作方式.
从应用程序的图标启动应用程序不会触发任何通知到您的应用程序,只会从横幅中触发.
如果你想奖励你的用户,即使他们没有点击横幅,你可能应该使用与触发你的通知相同的逻辑 - 只需计算自应用程序上次运行以来已经过去了多长时间,然后在那里做你的事情.

That's the way it works.
Starting the app from it's icon will not trigger any notifications to your app, only from the banner.
You should probably use the same logic as the one triggering your notification if you want to reward your users even though they didn't tap the banner - just calculate how long has it been since the app was last ran and do your stuff there.

这篇关于本地通知的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆