如何停止来自应用程序的通知

How to stop Notifications from the app

在一个开关中,我有一个通知触发器,可以重复自身。如何让它在开关关闭时停止?

let notification = UILocalNotification()
notification.fireDate = NSDate(timeIntervalSinceNow: 5)
notification.repeatInterval = NSCalendarUnit.Minute
notification.alertBody = "Please Look at me"
notification.soundName = UILocalNotificationDefaultSoundName
notification.userInfo = ["CustomField1": "w00t"]
guard let settings = UIApplication.sharedApplication().currentUserNotificationSettings() else { return }

您可以使用

取消所有本地通知
cancelAllLocalNotifications

或使用

浏览计划通知列表
scheduledLocalNotifications

并取消该特定通知(通过指定通知的 'userInfo' 字段进行标记)。