我有一个触发器可以向用户显示通知:
let content = UNMutableNotificationContent()
content.title = "Title"
content.body = "Body"
content.sound = UNNotificationSound.default
let trigger = UNTimeIntervalNotificationTrigger(timeInterval: 20, repeats: false)
let request = UNNotificationRequest(identifier: "TestIdentifier", content: content, trigger: trigger)
UNUserNotificationCenter.current().add(request, withCompletionHandler: nil)
一旦设置了触发器,您是否有办法取消它?
如何在时间间隔结束之前取消通知并调用通知?
removePendingNotificationsWithIdentifier
方法。您可以通过给定的标识符取消通知。 - Mannopson