Cancel UNNotificationRequest

ε祈祈猫儿з 提交于 2019-12-11 03:09:34

问题


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?


回答1:


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




回答2:


Swift 4

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

let center = UNUserNotificationCenter.current()
center.removeAllPendingNotificationRequests()


来源:https://stackoverflow.com/questions/45635400/cancel-unnotificationrequest

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!