UILocalNotification starts after reinstalling the application

My application has an alarm function using UILocalNotification, and it works great. However, if the user uninstalls the application and then REINSTALLS it, he will receive all the β€œintermediate” notifications at once.

I tried to call:

[[UIApplication sharedApplication] cancelAllLocalNotifications]; 

if this is the first time the application is launched, but it does not help, because the notification was received even before the application: the didFinishLaunchingWithOptions method is called:

It was worse in 4.0 when the alarm was repeated even if the user uninstalled the application, but at least this error was fixed by Apple in a later release. However, now I'm stuck with this. Anyone have an idea?

+6
iphone repeat notifications alarm uilocalnotification
source share
2 answers

This is actually a bug in the iPhone. If you uninstalled the application and installed it later, it will have the same application identifier, therefore, when the application is reinstalled, all past local notifications were launched even if you did not open the application.

+6
source share

According to Apple, this is not a bug (I filed a bug report). The system stores UILocalNotifications for remote applications for 24 hours in case the user accidentally uninstalls the application, and restores the specified UILocalNotifications if the application is re-installed during this time frame.

The solution would be to remove all UILocalNotifications on first run, for example:

 - (BOOL) application: (UIApplication*) application didFinishLaunchingWithOptions: (NSDictionary*) launchOptions { if (self.isFirstRun) { [[UIApplication sharedApplication] cancelAllLocalNotifications]; self.firstRun = NO; } /* Other code here */ ... } 

of course, implement your own firstRun setter and getter to retrieve / save to persistent storage like NSUserDefaults .

+15
source share

All Articles