【问题标题】:Is it possible to delete specific push notifications from the Notification Center?是否可以从通知中心删除特定的推送通知?
【发布时间】:2019-08-09 17:14:06
【问题描述】:

我希望能够从通知中心删除特定发送的推送通知。

UNUserNotificationCenter.current().removeAllDeliveredNotifications() 显然不能使用,因为它会删除所有内容。

UNUserNotificationCenter.current().removePendingNotificationRequests(withIdentifiers) 可以用于本地通知,您可以在创建和发布通知时设置标识符。 但是,似乎没有办法为推送通知设置标识符,如果您实现通知服务扩展,似乎没有办法在推送之前在其中设置标识符,也没有任何方法可以获取任何东西操作系统分配的内部标识符。

因此实际上是否可以从通知中心删除特定的推送通知?

【问题讨论】:

    标签: ios


    【解决方案1】:

    根据文档,您可以使用removeDeliveredNotifications(withIdentifiers:) 方法从通知中心删除特定通知。

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

    您也可以根据identifier 的文档为远程通知指定一个标识符:

    对于远程通知,它设置为 您在 APNs 请求标头中指定的 apns-collapse-id 键 生成远程通知时。如果没有设置值,则 系统会自动分配一个标识符。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-05-06
      • 2018-04-28
      相关资源
      最近更新 更多