Programmatically remove deleted notifications from action center

How can we pragmatically remove any pending remote notifications sent for my app from notification center. I want to clear them when the application starts.

I tried with API [[UIApplication sharedApplication] cancelAllLocalNotifications];

but didn't help.

PS: This question is specific to iOS 10 and the old streams are not duplicates for this.

+4


source to share


5 answers


At last...

It works like a charm!



[[UNUserNotificationCenter currentNotificationCenter] removeAllDeliveredNotifications];

      

+10


source


You can clear all notifications from notification center using these simple lines of code

[[UIApplication sharedApplication] setApplicationIconBadgeNumber: 1];
[[UIApplication sharedApplication] setApplicationIconBadgeNumber: 0];
[[UIApplication sharedApplication] cancelAllLocalNotifications];

      

use wherever you want. For my part, I used when the user clicked the logout button. You can use in



- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions

      

method for clearing notifications after opening the app

0


source


AFAIK, you should do this using the background for remote notifications and then respond to those notifications by sending local notifications. You can delete local notifications, but not remote notifications.

0


source


Resetting the app icon number will also remove all notifications (local and remote) from the action center.

Objective C

[UIApplication sharedApplication].applicationIconBadgeNumber = 0;

      

Swift

UIApplication.shared.applicationIconBadgeNumber = 0

      

0


source


This can of course be achieved with the removeDeliveredNotifications (withIdentifiers :) method available in UserNotifications.framework.

For detailed tutorial please follow this

https://medium.com/@sebastianosiski/implementing-removable-remote-notifications-on-ios-a17d74832bde

0


source







All Articles