2012-11-01 70 views
0

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

这里是我的代码:

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

我希望得到任何帮助。

回答

0

这就是它的工作方式。
从其图标启动应用程序不会触发任何通知到您的应用程序,只能从横幅中触发。
如果您想要奖励用户,即使他们没有点击横幅广告,也应该使用与触发您的通知的逻辑相同的逻辑 - 只需计算自应用上次运行以来的运行时间并在此处执行操作即可。