2012-11-01 137 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

這就是它的工作方式。
從其圖標啓動應用程序不會觸發任何通知到您的應用程序,只能從橫幅中觸發。
如果您想要獎勵用戶,即使他們沒有點擊橫幅廣告,也應該使用與觸發您的通知的邏輯相同的邏輯 - 只需計算自應用上次運行以來的運行時間並在此處執行操作即可。