Reputation:
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??
Upvotes: 5
Views: 279
Reputation:
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
Upvotes: 1
Reputation: 11700
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"];
}
Upvotes: 2
Reputation: 1528
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...
Upvotes: 1