Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

cancelAllLocalNotifications With Multiple LocalNotifications

I have a scenario where I schedule two separate LocalNotifications. One is set to fire at ten past midnight and the other fires every hour. I can distinguish between them by setting the UserInfo for the notification when I am scheduling it.

For the hourly notification I create an item in Core Data each time that notification fires. But the problem is that for the hourly notification I am getting a lot of extra items in Core Data each time it fires.

I am NOT calling the following line of code because calling it it seems to also cancel my notification that is supposed to fire after midnight.

[[UIApplication sharedApplication] cancelAllLocalNotifications];

How should I use cancelAllLocalNotifications when I have multiple scheduled LocalNotifications?

like image 631
motionpotion Avatar asked Jan 21 '26 14:01

motionpotion


1 Answers

Yes, as you see. cancelAllLocalNotifications, as it's name suggests, will cancel everything. Yes, also, you should use the userInfo to differentiate between your notifications.

To manage / remove your notifications selectively you should get all of the registered notifications with scheduledLocalNotifications, then iterate over them checking the userInfo, then call cancelLocalNotification with the ones you no longer need.

like image 168
Wain Avatar answered Jan 24 '26 07:01

Wain



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!