iOS 9.2.1, cancel notifcation not working

102 Views Asked by At

I'm developing an app having local notification scheduled. I'm not able to cancel the scheduled notification using the code:

UIApplication *app=[UIApplication sharedApplication];  
[app cancelLocalNotification:notification];

The code is working well in previous iOS versions, but it is stopped working in iOS 9.2.1 update.

Can anyone please help me to sort out the issue?

2

There are 2 best solutions below

0
On BEST ANSWER

There is a bug in iOS 9.2.1, so cancelLocalNotification methods doesn't work sometimes. Use cancelLocalAllNotifications and update your logic accordingly. This should work.

0
On

Keep your localnotification object in NSUSerDefault when it is scheduling, even if your device gets restart you can retrieve localnotification object from NSUSerDefault. So then after you can easily pass that object in cancelLocalNotification(localNotificationObject) and remove it.