How to remove specific remote notification in the notification center
Asked Answered
S

2

8

We all know that this method [UIApplication sharedApplication].applicationIconBadgeNumber = 0; could remove all remote notifications of our application from the notification center. However, for some reason, I want to remove the one which user taps on the notification center, and leave the others.

Does it have any method to do it?

Sombrero answered 21/12, 2014 at 17:2 Comment(0)
N
4

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://mcmap.net/q/392403/-remove-single-remote-notification-from-notification-center

Nitrogenous answered 21/12, 2014 at 17:15 Comment(2)
@Sombrero Please mark this as answered and upvote it if you believe it is the answer.Nitrogenous
Starting iOS 10, this is possible too. Check my answer https://mcmap.net/q/1294093/-how-to-remove-specific-remote-notification-in-the-notification-centerStuyvesant
S
8

With introduction of UNUserNotificationCenter for iOS 10 and above, it is now possible to remove few or all remote notifications of your app.

UNUserNotificationCenter documentation

With a shared singleton instance of this class, it is possible to manage delivered remote notifications on the device. Specifically, the following methods can be used: func removeDeliveredNotifications(withIdentifiers: [String]) if you want to remove specific notification of your app, OR func removeAllDeliveredNotifications() to remove all notifications of your app.

Stuyvesant answered 12/5, 2017 at 16:46 Comment(0)
N
4

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://mcmap.net/q/392403/-remove-single-remote-notification-from-notification-center

Nitrogenous answered 21/12, 2014 at 17:15 Comment(2)
@Sombrero Please mark this as answered and upvote it if you believe it is the answer.Nitrogenous
Starting iOS 10, this is possible too. Check my answer https://mcmap.net/q/1294093/-how-to-remove-specific-remote-notification-in-the-notification-centerStuyvesant

© 2022 - 2024 — McMap. All rights reserved.