when i set an local notification for an upcoming time and when deleted the app, the local notification triggers while i re installed the app. Is there any method to avoid this. Why this happens??
Asked
Active
Viewed 275 times
3 Answers
2
Maybe in applicationDidFinishLaunching (not tested):
NSUserDefaults *prefs = [NSUserDefaults standardUserDefaults];
BOOL firstRun = [prefs boolForKey:@"firstRun"];
if(firstRun) {
// Cancel all UILocalNotifications
} else {
BOOL firstRun = NO;
[prefs setBool:firstRun forKey:@"firstRun"];
}

Peter Warbo
- 11,136
- 14
- 98
- 193
1
If there was a callback when your app was deleted you could [[UIApplication sharedApplication] cancelAllLocalNotifications];
however as this is not possible I don't see any way...

Jonathan King
- 1,528
- 14
- 25
1
You should implement like below code in application didFinishLaunchingWithOptions, Hope this can be working.
NSUserDefaults *prefs = [NSUserDefaults standardUserDefaults];
// BOOL firstRun=YES;
BOOL firstRun = [prefs boolForKey:@"firstRun"];
if(firstRun) {
NSArray *notificationarray = [[UIApplication sharedApplication] scheduledLocalNotifications];
BOOL firstRun =NO;
[prefs setBool:firstRun forKey:@"firstRun"];
} else {
BOOL firstRun = NO;
[prefs setBool:firstRun forKey:@"firstRun"];
NSArray *notificationarray = [[UIApplication sharedApplication] scheduledLocalNotifications];
NSLog(@"%@",notificationarray);
}
[prefs synchronize];
Hope this helps

Maulik
- 19,348
- 14
- 82
- 137