2012-05-26 36 views
0

我最近做了一個包含本地通知的客戶端應用程序。在原始版本中,通知工作得很好。但是,當客戶端試圖發佈另一個版本時,只更改了圖像和數據庫資源,代碼中沒有任何更改,通知就停止工作。現在我一直在試圖調試代碼,但一無所獲。一切似乎都很好,但沒有通知。同時,如果我運行較早的版本,它的工作完美。你能幫我解決什麼可能是錯的嗎?非常感謝你花時間陪伴。本地通知停止出現?

NSTimeInterval diffTimeIntervalSinceNow = timeInterval; //time-interval after which notification should appear 


    UILocalNotification *localNotification = [[UILocalNotification alloc] init]; //Create the localNotification object 
    [localNotification setFireDate:[NSDate dateWithTimeIntervalSinceNow:diffTimeIntervalSinceNow]]; //Set the date when the alert will be launched using the date adding the time the user selected on the timer 
    //[localNotification setRepeatInterval:notificationInterval]; 

    [localNotification setAlertAction:@"Launch"]; //The button's text that launches the application and is shown in the alert 
    [localNotification setAlertBody:alertBody]; //Set the message in the notification from the textField's text 
    [localNotification setHasAction: YES]; //Set that pushing the button will launch the application 
    [localNotification setApplicationIconBadgeNumber:[[UIApplication sharedApplication] applicationIconBadgeNumber]+1]; //Set the Application Icon Badge Number of the application's icon to the current Application Icon Badge Number plus 1 

    [[UIApplication sharedApplication] cancelAllLocalNotifications]; 
    [[UIApplication sharedApplication] scheduleLocalNotification:localNotification]; //Schedule the notification with the system 
    [localNotification release]; 

這就是我一直在使用的代碼。但是,這是在早期版本中工作的完全相同的代碼。

回答

0

我糾正你的代碼: - 試試這個: - 在按鍵操作或內部的任何方法

[[UIApplication sharedApplication] cancelAllLocalNotifications]; 
     NSTimeInterval diffTimeIntervalSinceNow = timeInterval; //time-interval after which notification should appear 


      UILocalNotification *localNotification = [[UILocalNotification alloc] init]; //Create the localNotification object 
      [localNotification setFireDate:[NSDate dateWithTimeIntervalSinceNow:diffTimeIntervalSinceNow]]; //Set the date when the alert will be launched using the date adding the time the user selected on the timer 
      //[localNotification setRepeatInterval:notificationInterval]; 

      [localNotification setAlertAction:@"Launch"]; //The button's text that launches the application and is shown in the alert 
      [localNotification setAlertBody:alertBody]; //Set the message in the notification from the textField's text 
      [localNotification setHasAction: YES]; //Set that pushing the button will launch the application 
      [localNotification setApplicationIconBadgeNumber:[[UIApplication sharedApplication] applicationIconBadgeNumber]+1]; //Set the Application Icon Badge Number of the application's icon to the current Application Icon Badge Number plus 1 


      [[UIApplication sharedApplication] scheduleLocalNotification:localNotification]; //Schedule the notification with the system 
      [localNotification release]; 

這個工作: - 檢查這個方法在應用程序委託得到一些事件或不

-(void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notification 
{ 

} 

要取消所有通知,請使用此功能

+0

沒有什麼變化。我猜代碼是好的因爲我把兩個類與'fileMerge'進行了比較,並且沒有任何區別。 – Ahmed

0

可能是您的客戶端還修改alertBody,並且新的alertBody的長度過長?