Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to remove specific remote notification in the notification center

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?

like image 510
Don_Chen Avatar asked Dec 21 '14 17:12

Don_Chen


People also ask

What are remote notifications in Android?

Remote Notifications are notifications sent to a mobile device using a data-channel from a service provider in real-time.

How do I manage my notification center?

To find your notifications, from the top of your phone screen, swipe down. Touch and hold the notification, and then tap Settings . Choose your settings: To turn off all notifications, turn off All notifications.

What is remote push notification?

Overview. Use remote notifications (also known as push notifications) to push small amounts of data to devices that use your app, even when your app isn't running. Apps use notifications to provide important information to users. For example, a messaging service sends remote notifications when new messages arrive.


2 Answers

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.

like image 72
Mehul Parmar Avatar answered Sep 16 '22 19:09

Mehul Parmar


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

like image 20
Kyle Robson Avatar answered Sep 20 '22 19:09

Kyle Robson