在 Swift 3 中从锁定屏幕清除本地通知

Clear local notification from lock screen in Swift 3

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

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

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