简体   繁体   中英

Deleting notifications from the notification center revisited

The previous posting on here regarding deleting notifications from the notification center claim its not possible to delete individual notifications, only all of them.

However individual notifications do get deleted for the reminder app - set 3 reminders to fire in a couple of minutes, when they fire go to the notification center, now select one, after the reminder app launches go back to the notification center and that specific notification has been deleted but others remain. So how is this achieved?

The Reminders app probably fires local notifications. Local notifications can be withdrawn, using cancelLocalNotification: on UIApplication .

(Additionally, push notifications when sent using the enhanced call (first byte is 1) supports an expiry parameter (when sending, not inside the JSON payload) that is supposed to mean that this notification, if not delivered by a certain date, should not be delivered. It is possible that this parameter is also used in a similar way to hide received notifications.

It is also highly possible that Apple's own apps do whatever the hell they want.)

When the user taps on the notification:

  • If the app was running in the background, you retrieve it using AppDelegate's method didReceiveLocalNotification.
  • If it wasn't running, then the notification can be obtained with the didFinishLaunchingWithOptions method. You just need to search the launchOptions dictionary for the UIApplicationLaunchOptionsLocalNotificationKey.

If you want to delete specific notifications which have already fired, specially when the user doesn't enter the app by tapping on the notification, then it's probably better to store them in NSUserDefaults so that you can still obtain them later. That approach is explained here .

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