ios - 从 Swift 3 中的锁屏清除本地通知

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

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

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

最佳答案

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

关于ios - 从 Swift 3 中的锁屏清除本地通知,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41212985/

相关文章:

ios - iPhone SDK : Core Data

javascript - Phone Gap 是否能够将 php web 应用程序转换为 iphone/android 应用程序?

ios - NSOperationQueue 和传递数据

iphone - NSOperationQueue 在 iPhone 上不重用线程

objective-c - 在 Xcode 中为 iPad 指定图像,例如为 iPhone 4 指定 @2x

javascript - 检测客户端是否允许 HTML5 视频的内​​联媒体播放

ios - 移动我的 SpriteNode Swift SpriteKit

swift - 这是什么意思?变量声明后跟一个没有赋值的 block

swift - 如何在我的 swift UI View 中添加 'skyfloatLabelText'?

ios - 是否可以创建 NSFetchedResultsController 来获取特定属性具有不同值的所有实体?