Remotely remove previously sent notification

烂漫一生 提交于 2019-12-22 12:19:31

问题


Since iOS 10 and UNUserNotificationCenter, a lot of things can be achieved with notifications, but I can't figure out how to remotely remove a push notification every time.

Using the mutable-content attribute, I'm able to modify the content of my push notification. But let's say I want to remove it later (the content has expired). I used content-available and then the following code:

UNUserNotificationCenter.current()
                        .removeDeliveredNotifications(withIdentifiers: [xxx])

It almost works, except (and that's a major problem) when the app was swiped out of memory by the user.

Has anyone found a way to remove notifications?


回答1:


As mentioned in this SO answer we have to send another push notification to clear previously sent notifications.

That notification should contain badge:0, and omit the alert and sound fields, then it will remove notifications from notification centre as well as clear app badge.



来源:https://stackoverflow.com/questions/41289348/remotely-remove-previously-sent-notification

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