2012-07-04 65 views
18

我在App Store中有本地通知的應用程序。從App Store更新後,應用程序失去對本地通知的控制

在我的應用程序的最近4個版本更新中,有些客戶遇到了一些奇怪的事情 - 應用程序失去了對以前通知的控制權,他們不斷收到更新前的所有通知,即使它們應該被[[UIApplication sharedApplication] cancelAllLocalNotifications]

在與這些客戶進行溝通時,我告訴他們關閉提醒,執行cancelAllLocalNotifications,但他們聲稱會不斷收到提醒。

此外,重新安裝應用程序不會擺脫舊的通知!就好像iOS認爲這是一個不同的應用程序。

這不會發生在我的大部分客戶身上,只有極少數人 - 但仍然會發生每一次更新!

這怎麼可能?

更新

在3年後,它仍然發生。

每個更新一些客戶不斷收到本地通知,但應用程序無法看到這些,也無法控制它們。

任何人都可以解決這個問題或證明它是一個iOS的bug?

+0

他們不能只是刪除並重新安裝應用程序?顯然有些奇怪的事情已經發生。所以最好再次開始。也許它是蘋果公司7月4日更新錯誤的一部分? –

+0

「重新安裝應用程序不會擺脫舊的通知」,其中一些嘗試。這與4月7日無關,因爲它也發生在前兩次更新中。 – Kof

+0

順便說一句 - 我已經打開了一張蘋果票,他們無法找到原因。 – Kof

回答

2

你有沒有檢查How does UIApplication cancelAllLocalNotifications work between app updates? 它沒有明確的答案,但它可能會有用。

嘗試找出有什麼特殊之處,遇到這種顧客:

  • 是否總是誰遇到這種情況同客戶?
  • 他們使用哪個iOS版本?
  • 他們如何以不同的方式使用您的應用程序?預定了很多通知?
  • 他們如何進行更新? (空中下載,同步等)
+0

1.不一樣的客戶,每次都不一樣。我會與他們覈對。 3.所有客戶都有相同數量的預定通知。我會檢查。 – Kof

+0

不是答案,也沒有解決我的問題,但我必須給予某人賞金獎勵。 – Kof

0

將下面的代碼添加到您的應用程序中:didFinishLaunchingWithOptions:方法來清除所有通知。

[[UIApplication sharedApplication] setApplicationIconBadgeNumber: 1]; 
[[UIApplication sharedApplication] setApplicationIconBadgeNumber: 0]; 
[[UIApplication sharedApplication] cancelAllLocalNotifications]; 

完成後,您可以添加新的通知。

+0

這已經發生,並沒有幫助。 – Kof

1

我有類似的問題與通知。我實際刪除的解決方案是設置一個特定的日期,只通知一次。 applicationIconBadgeNumber = 0行從通知列表中刪除通知。徽章號碼僅在用戶進入應用程序時設置。對於用戶還沒有看到消息的情況,您可以在applicationWillEnterForeground中添加一個檢查,並顯示與通知相同消息的適當UIAlertView,並且可以使用notificationArray以類似的方式獲取最後的通知。當您需要設置新通知時,「isNotified」需要setValue:@「0」並進行同步。當我使用多個通知時,我保存這樣的狀態:

[userDefaults setValue:@"1" forKey:[NSString stringWithFormat:@"notification-%@", @"12"]]; 
NSInteger number = [[userDefaults objectForKey:[NSString stringWithFormat:@"notification-%@", @"12"]] integerValue]; 

在MainViewController中。米

NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults]; 
NSInteger alreadyNotified = [[userDefaults objectForKey:@"isNotified"] integerValue]; 

if (alreadyNotified == 0) { 

    NSInteger seconds = 60; 
    NSString *message = @"Just testing!"; 

    UILocalNotification *notification = [[UILocalNotification alloc] init]; 

    UIUserNotificationSettings *currentSettings = [[UIApplication sharedApplication] currentUserNotificationSettings]; 
    BOOL allowNotif = (currentSettings.types != UIUserNotificationTypeNone); 
    BOOL allowsSound = (currentSettings.types & UIUserNotificationTypeSound) != 0; 
    BOOL allowsBadge = (currentSettings.types & UIUserNotificationTypeBadge) != 0; 
    BOOL allowsAlert = (currentSettings.types & UIUserNotificationTypeAlert) != 0; 

    if (notification) 
    { 
     if (allowNotif) 
     { 
      NSDate *now = [NSDate date]; 
      if (seconds > 0) { 
       now = [now dateByAddingTimeInterval:seconds]; 
      } 
      notification.fireDate = now; 
      notification.timeZone = [NSTimeZone timeZoneWithName:@"UTC"]; 
      notification.repeatInterval = 0; 
      NSDictionary *userInfo = [NSDictionary dictionaryWithObjectsAndKeys:@"1", @"id", message, @"message", nil]; 
      notification.userInfo = userInfo; 
     } 
     if (allowsAlert) 
     { 
      notification.alertBody = message; 
     } 
     if (allowsBadge) 
     { 
      notification.applicationIconBadgeNumber = 1; 
     } 
     if (allowsSound) 
     { 
      notification.soundName = UILocalNotificationDefaultSoundName; 
     } 

     [[UIApplication sharedApplication] scheduleLocalNotification:notification]; 

     NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults]; 
     [userDefaults setValue:@"1" forKey:@"isNotified"]; 
     [userDefaults synchronize]; 
    } 

} else { 

    UIApplication *app = [UIApplication sharedApplication]; 
    NSArray *notificationArray = [app scheduledLocalNotifications]; 
    for (int i=0; i<[notificationArray count]; i++) 
    { 
     UILocalNotification *notification = [notificationArray objectAtIndex:i]; 
     [app cancelLocalNotification:notification]; 
    } 
} 

在AppDelegate.m

- (void)applicationWillEnterForeground:(UIApplication *)application { 
    application.applicationIconBadgeNumber = 0; 
} 
+0

這種方法在讀取它們後直接刪除所有通知,因此在應用程序更新後它不應觸發舊通知。至少它不會在我的應用程序中這樣做。我剛剛嘗試重新安裝,只顯示了新的(先前未顯示的)計劃通知。 –

-1

嘿,這是什麼也與我的應用程序發生爲好。我的本地通知解僱下面scenerios:
1.用戶已刪除該應用程序

  • 在同一臺設備,但不同的用戶名使用相同的應用程序,他們得到警報上次登錄在用戶中。
  • -Actually其UILocalNotification的行爲,我們不得不取消他們別的IOS留住他們至少一段時間(不知過了多久),當應用程序被刪除,他們通過在刪除時間的應用程序安排,並沒有取消。

    因此,一定要確保您的應用程序安裝發生時,保持檢查&取消所有計劃的通知。

    - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions 
    
        if(//its a fresh install){ 
    
        [[UIApplication sharedApplication] cancelAllLocalNotifications]; 
    
        } 
    
    
        } 
    

    cancelAllLocalNotifications將取消現有的所有通知。

    希望它會有所幫助。

    +0

    不正常,如前所述,'cancelAllLocalNotifications'已被多次調用,並沒有停止舊的通知。 – Kof

    相關問題