I’m trying to remove notifications from the notification center.
I found out the following code which has been supplied by another stackoverflow user:
[[UIApplication sharedApplication] setApplicationIconBadgeNumber: 0];
I tried adding that code to the AppDelegate.m below
applicationWillEnterForeground
But whenever I tap a notification from the notification center it doesn’t go away in the notification center itself.
What am I doing wrong?
I can’t use “CancelAllNotifications” because I have pre-scheduled notifications in the future to.
From my tests, it looks like we need to cancel the existing local notifications in addition to calling
setApplicationIconBadgeNumber:Since you want to keep any upcoming notifications in the system, just doing a simple cancel obviously won’t work. Therefore the strategy I’d go with is to add those remaining notifications to a new array, and then re-set that array as the collection of
scheduledLocalNotifications.It may seem a bit odd to read the collection and then re-set it, however according to the documentation, setting thescheduledLocalNotificationsproperty invokescancelLocalNotification:first… which is exactly what we want to do.