Cancel UNNotificationRequest
Asked Answered
P

2

5

Because UILocalNotification is now deprecated, I moved my code to the new UNNotificationRequest API.

It states: 'cancelLocalNotification' was deprecated in iOS 10.0: Use UserNotifications Framework's -[UNUserNotificationCenter removePendingNotificationRequestsWithIdentifiers:]

But it seems that it is not equal - while I could remove messages with cancelLocalNotification at any time (even they are displayed/delivered) it seems that removePendingNotificationRequestsWithIdentifiers only removes undelivered notifications. That's really annoying.

So my question is: Is there a valid way removing notifications queued with UNNotificationRequest or should I just ignore those deprecation warnings?

Peak answered 11/8, 2017 at 12:35 Comment(2)
see this once #40563412Insignificancy
@Insignificancy that question only mentions pending notifications as well and OP was looking for delivered notifications.Woodwind
W
7

You can also use the removeDeliveredNotifications(withIdentifiers:) function to remove already delivered notifications from the notification center. For more info, see the documentation

Woodwind answered 11/8, 2017 at 12:50 Comment(0)
Y
4

Swift 4 and Swift 5

If you want to remove all UNNotificationRequest items, you can use:

let center = UNUserNotificationCenter.current()
center.removeAllPendingNotificationRequests()
Yelena answered 19/4, 2018 at 5:14 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.