Reputation: 18487
I have an app I am working on with allows the user to set and remove UILocalNotifications. In the course of developing this I have added and removed UILocalNotifications for testing and it seems to be working.
However I am seeing strange behavior where, after deleting my app from the device and running it again without setting any notifications, I will get a UILocalNotification. This notification was not set in this fresh install (checked through adding a breakpoint in my notification setup method).
Is it possible that I have an orphaned UILocalNotification from a previous install (yes, it seems highly unlikely to me too).
I've tried debugging this by setting the notification alertBody
to something specific to each new install but this unique string doesn't get displayed in the alert. For example:
notif.alertBody = [NSString stringWithFormat:@"Alert for: %@", alertName];
Has anyone seen this sort of behavior before?
Update: Just confirmed orphaned UILocalNotifications: deleted the app from the device and ran the code below in my rootViewController on viewDidAppear
. I get the following output in the Console:
2013-03-14 14:20:07.439 TestApp[16606:907] found alert: uigffhy 2013-03-14 14:20:07.444 TestApp[16606:907] found alert: uigffhy
Where this user was from some previous install. Ugh.
NSArray *notificationArray = [[UIApplication sharedApplication] scheduledLocalNotifications];
for (UILocalNotification *notif in notificationArray) {
NSDictionary * info = notif.userInfo;
NSString * name = [info objectForKey:@"sequenceName"];
NSLog(@"found alert: %@", name);
}
Upvotes: 0
Views: 128
Reputation: 1414
Just detect if it's a fresh install (using NSUserDefaults
) and do the following in applicationDidFinishLaunching:
[[UIApplication sharedApplication] cancelAllLocalNotifications];
Upvotes: 1