【问题标题】:Clear local notification from lock screen in Swift 3从 Swift 3 中的锁定屏幕清除本地通知
【发布时间】:2016-12-18 21:18:28
【问题描述】:

我只想在任何给定时间在我的锁定屏幕上显示一个本地 iOS 通知。

在特定通知上调用 cancelLocalNotification 似乎是一种笨拙的方法(在 iOS10 中已弃用)。有什么方法可以在推送新的本地重复通知之前删除所有通知?

【问题讨论】:

    标签: ios iphone swift push-notification apple-push-notifications


    【解决方案1】:

    您可以调用 UIApplication 方法 - cancelAllLocalNotifications
    它在 iOS 10 中已弃用,因为 iOS 10 具有新的 UNNotification 类。
    如果你使用这些 - 你可以使用 UNUserNotificationCenter 方法 removeAllPendingNotificationRequestsremoveAllDeliveredNotifications 来删除已经发送的通知。

    【讨论】:

    • 什么时候打电话比较合适?当即将发送 UNNotification 时,没有委托选项。
    • @arooo 我想最好的时间是在提交新通知之前,根据你写的关于你的用例的内容。
    • 哦,对于 iOS 10,当使用 UINotification - 也可以使用 UINotificationCenter. removeAllDeliveredNotifications 删除所有已发送的通知。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-04-06
    • 2022-07-01
    • 2021-07-21
    相关资源
    最近更新 更多