【发布时间】:2019-08-14 22:06:59
【问题描述】:
我有一个向用户显示通知的触发器:
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)
有没有办法让我在设置触发器后取消它?
如何在timeInterval用完之前取消通知并调用通知?
【问题讨论】:
-
你问这个是什么意思?系统只计算活动通知。
-
@Mannopson 我问,假设我在 15 分钟内打开了一个触发器以显示本地通知,但 10 分钟后我想取消该触发器以不显示通知我该怎么做?
-
使用
removePendingNotificationsWithIdentifier。您可以通过给定的标识符取消通知。 -
@Mannopson 你能把它写成答案吗?我给你正确答案
标签: swift unusernotificationcenter unnotificationrequest