从App Store更新后,应用程序失去了对本地通知的控制

我有一个在App Store本地通知的应用程序。

在我的应用程序的最近4个版本更新中,有些客户经历了一些奇怪的事情 – 应用程序失去了对先前通知的控制权,他们不断收到更新前的所有通知,尽pipe它们应该被[[UIApplication sharedApplication] cancelAllLocalNotifications]

在与这些客户进行沟通时,我告诉他们closures提醒,即执行cancelAllLocalNotifications提醒,但他们声称不断提醒。

此外,重新安装应用程序不会摆脱旧的通知! 就好像iOS认为这是一个不同的应用程序。

这不会发生在我的大部分客户身上,只有极less数客户 – 但是,每一次更新都会发生!

怎么会这样?

更新

3年后,它仍然在发生。

每次更新一些客户不断收到本地通知,但应用程序不能看到这些,也不能控制它们。

任何人都可以解决这个问题,或者certificate这是一个iOS的错误?

您是否检查了应用程序更新之间的UIA应用程序cancelAllLocalNotifications是如何工作的? 它没有明确的答案,但也许是有用的。

试着找出体验到这一点的客户有什么特别之处:

  • 是否经常遇到这种行为的客户?
  • 他们使用哪个iOS版本?
  • 他们如何使用你的应用程序不同? 预定了很多通知?
  • 他们如何进行更新? (无线电,同步等)

我有类似的通知问题。 我实际删除的解决scheme是设置一个特定的date,只通知一次。 applicationIconBadgeNumber = 0行从通知列表中删除通知。 徽章号码仅在用户进入应用程序时设置。 对于用户还没有看到消息的情况,您可以在applicationWillEnterForeground中添加一个检查,并显示与通知相同的消息,并使用notificationArray以类似的方式获取最后一个通知。 当你需要设置一个新的通知“isNotified”需要setValue:@“0”并被同步。 当我使用多个通知时,我保存这样的状态:

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

在MainViewController.m中

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

将下面的代码添加到您的应用程序:didFinishLaunchingWithOptions:方法来清除所有通知。

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

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

嘿,这也是我的应用程序也发生了什么。 我的本地通知正在下面的scenerios被解雇:
1.用户已经删除了该应用程序

  1. 在同一设备上使用相同的应用程序,但使用不同的用户名,他们获取最后login用户的警报。

事实上,它的UILocalNotification行为,我们必须取消它们,否则IOS保留至less一段时间(不知道多久),当应用程序被删除,他们在应用程序删除时间,并没有取消。

因此,请务必确保您的应用安装发生时,请检查并取消所有预定的通知。

喜欢

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

cancelAllLocalNotifications将取消所有现有的通知。

希望它会有所帮助。