2012-10-31 127 views
1

因此,我的應用程序已經存在了5天,iPhone 3GS用戶報告說他們的通知在按鈕切換時不會取消。 按鈕執行以下代碼:cancelAllLocalNotifications;不適用於iPhone 3GS

[[UIApplication sharedApplication] cancelAllLocalNotifications]; 

然而,這個代碼工作在iPhone 4,iPhone 4S,iPhone 5和iPad。 這是iPhone 3GS的一個已知錯誤嗎?或者3GS需要不同的代碼才能實現相同的目標?

回答

0

不知道爲什麼,但我不得不取消由notifcation ID而不是CancelAll所有通知在iPhone 3GS

1

我在iPhone上運行6+這個問題在iOS 8.1。事實證明,cancelAllLocalNotifications不是一個同步調用,因此無法保證取消在返回時已完成。我不得不實施以下解決方法

- (void) clearNotifications 
{ 
    NSLog(@"Clearing notifications"); 
    [[UIApplication sharedApplication] cancelAllLocalNotifications]; 
    long count; 
    while ((count = [[[UIApplication sharedApplication] scheduledLocalNotifications] count]) > 0) { 
     NSLog(@"Remaining notificaitons to cancel: %lu",(unsigned long)count); 
     [NSThread sleepForTimeInterval:.01f]; 
    } 
    NSLog(@"Notifications cleared"); 
} 
+0

此方法適用於我,但您能解釋什麼是sleepForTimeInterval? – Lixu

相關問題