问题
The notification is firing even after it is cancelled. I tried checking cancelling method it turned out to be correct.
When I cancel a notification, the notification is again fired the next day
- (void)cancelNotification:(int)bookID
{
NSArray *notifications = [[UIApplication sharedApplication] scheduledLocalNotifications];
NSLog(@"Cancelling... Before %d",[[[UIApplication sharedApplication]scheduledLocalNotifications]count]);
for (UILocalNotification *notification in notifications)
{
int notifRemedyId = [[notification.userInfo objectForKey:@"kRemindMeNotificationRemedyIDKey"]intValue];
NSLog(@"remedyID : %d",remedyId);
NSLog(@"notifyId : %d",notifRemedyId);
if (remedyId == notifRemedyId)
{
[[UIApplication sharedApplication] cancelLocalNotification:notification];
}
}
}
I am thinking its because of repeatInterval.should repeatInterval property be removed.
SO I wanted to know where I am going wrong.
回答1:
1) First check retrieved particular notification object is not nil. Also check if that is the notification you want to cancel.
2) When you are sure notification object is not nil and the notification is the desired one, then fire below command. notification is your desired notification object.
[[UIApplication sharedApplication] cancelLocalNotification:notification];
3) I am looking at your code and I could see that you are not using bookID
notification anywhere in your code. Not sure if you are using that code anymore.
4) No, you don't need to do anything extra to cancel repeating notification
Note: Please update your Question with final updated code. This looks confusing.
来源:https://stackoverflow.com/questions/16477894/uilocalnotification-firing-even-after-notification-is-cancelled