I would like to remove old notifications that my app has made from the iOS 5 Notification Center. Can I do this? If so, how?
5 Answers
To remove notifications from the Notification Center simply set your icon badge number to zero.
[[UIApplication sharedApplication] setApplicationIconBadgeNumber:0];
This only works if the number changes, so if your app doesn't use the badge number you have to first set, then reset it.
[[UIApplication sharedApplication] setApplicationIconBadgeNumber:1];
[[UIApplication sharedApplication] setApplicationIconBadgeNumber:0];

- 3,678
- 1
- 29
- 32
-
3This works...You have to set it to some value and then reset to 0......Thank you @voidStern – Meet Jun 22 '12 at 08:18
-
2Great answer, i tried everything, and this works. Also you can use dot syntax if that fits you more :) `[UIApplication sharedApplication].applicationIconBadgeNumber = 1; [UIApplication sharedApplication].applicationIconBadgeNumber = 0;` – WonderCsabo Jun 15 '13 at 18:44
-
Is this still needed on iOS >= 7? – Gian Franco Zabarino Sep 23 '15 at 17:23
A more straightforward method that I use (and doesn't require badges) is to reset the array of scheduled local notifications to itself, as follows:
UIApplication* application = [UIApplication sharedApplication];
NSArray* scheduledNotifications = [NSArray arrayWithArray:application.scheduledLocalNotifications];
application.scheduledLocalNotifications = scheduledNotifications;
This has the effect that any scheduled notifications remain valid, while all "old" notifications that are present in Notification Center are removed. However, it also has the feel of something that might change in a future release of iOS, as I haven't seen any documentation for this behavior.
Of course, if you want to remove all notifications, it's simply the following:
[[UIApplication sharedApplication] cancelAllLocalNotifications];

- 2,506
- 18
- 20
Yes, you can cancel specific or all local notifications by calling
[[UIApplication sharedApplication] cancelLocalNotification:...];
or
[[UIApplication sharedApplication] cancelAllLocalNotifications];

- 59
- 6
If you want to clear notifications in swift and iOS 10.0
import UserNotifications
if #available(iOS 10.0, *) {
let center = UNUserNotificationCenter.current()
center.removeAllPendingNotificationRequests() // To remove all pending notifications which are not delivered yet but scheduled.
center.removeAllDeliveredNotifications() // To remove all delivered notifications
}

- 8,350
- 38
- 53
- 109

- 8,075
- 1
- 24
- 27
For me it only worked with sending a local notification with only a badge like this:
if([UIApplication sharedApplication].applicationIconBadgeNumber == 0) {
UILocalNotification *singleLocalPush = [[UILocalNotification alloc] init];
singleLocalPush.fireDate = [NSDate dateWithTimeIntervalSinceNow:1];
singleLocalPush.hasAction = NO;
singleLocalPush.applicationIconBadgeNumber = 1;
[[UIApplication sharedApplication] scheduleLocalNotification:singleLocalPush];
[singleLocalPush release];
} else {
[[UIApplication sharedApplication] setApplicationIconBadgeNumber:0];
}
And in the method
-(void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notification
I can set the badge to 0 again.