简体   繁体   中英

iOS Clear individual / all notifications from Notification Center

I would like to clear delivered notifications from notification centre based on what a user does. So, if they view a certain screen, remove the relevant notification etc.

There may be more than one delivered notification for the app, but I may not want to clear all of them.

How can I list all the delivered notifications that are showing in notification centre from my app, and then programatically remove the relevant notification?

I have looked at this thread Can I programmatically clear my app's notifications from the iOS 5 Notification Center? however it does not seem to show how I can list delivered notifications so that I can then programatically remove the relevant one(s).

As per Martin H You can't do this. You can either delete them all or none of them. You can't delete individual ones.

I have several types of notifications and I selectively remove notifications based on user interactions. Simply reference the name of your Notification variable and remove it.

var notification_1:UILocalNotification = UILocalNotification()
....
var notification_1:UILocalNotification = UILocalNotification()
....
UIApplication.sharedApplication().cancelLocalNotification(notification_1)

It may not be the best method, but it seems to work. See this answer too: Removing a notification from notification center on click

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM