Remove Single Remote Notification from Notification Center

How to remove specific remote notification in the notification center

If you're simply looking to remove one number from the badge number:

[UIApplication sharedApplication].applicationIconBadgeNumber = MAX([UIApplication sharedApplication].applicationIconBadgeNumber - 1, 0);

If you're asking how to programmatically remove a single notification from notification center, it can't be done in code. Apparently in iOS8 the OS will remove a single notification when a user taps on it. Otherwise it's not possible to be handled by you.

See: https://stackoverflow.com/a/10569847/620577

Programmatically delete Remote Notifications from Notification Centre

Finally...

This one works like charm!

[[UNUserNotificationCenter currentNotificationCenter] removeAllDeliveredNotifications];

Is it possible to delete specific push notifications from the Notification Center?

As per the documentation you can remove a specific notification from the notification center using removeDeliveredNotifications(withIdentifiers:) method.

UNUserNotificationCenter.current().removeDeliveredNotifications(withIdentifiers: [yourNotificationIdentifier])

You can specify an identifier for the remote notification as well, as per the documentation of identifier:

For remote notifications, it is set to the value of the
apns-collapse-id key that you specified in the APNs request header
when generating the remote notification. If no value is set, the
system automatically assigns an identifier.

Remove single remote notification from Notification Center

There is no way to remove a specific notification as of iOS SDK 5.0. The way to remove all the notifications from your app so they don't show in the Notification Center when the user opens the app from one of them, is to set the app badge to 0, like this:

[UIApplication sharedApplication].applicationIconBadgeNumber = 0;

EDIT: on iOS 8, SpringBoard seems to be automatically dismissing a notification when you tap on it on the Notification Center to open the app.

Remove a particular push notification from notification center tray

Every notification has an identifier and after reading a notification you can simply do -

UNUserNotificationCenter.current().removeDeliveredNotifications(withIdentifiers: [notification_identifier_here])


Related Topics



Leave a reply



Submit