远程删除以前发送的通知 [英] Remotely remove previously sent notification

查看:26
本文介绍了远程删除以前发送的通知的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

从 iOS 10 和 UNUserNotificationCenter 开始,很多事情都可以通过通知来实现,但我不知道如何远程删除推送通知每次.

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.

使用 mutable-content 属性,我可以修改推送通知的内容.但是假设我想稍后删除它(内容已过期).我使用了 content-available 然后是下面的代码:

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?

推荐答案

这个 SO 答案中所述,我们必须发送另一个推送通知以清除之前发送的通知.

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

该通知应包含 badge:0,并省略 alertsound 字段,然后它也会从通知中心删除通知作为清晰的应用标志.

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.

这篇关于远程删除以前发送的通知的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆