【发布时间】:2023-04-10 16:08:01
【问题描述】:
我有一个 UNUserNotificationCenter 每 60 秒发送一次本地通知。它的实现如下:
let userNotificationCenter = UNUserNotificationCenter.current()
let notificationContent = UNMutableNotificationContent()
notificationContent.title = "Test title"
notificationContent.body = "Test body"
let trigger = UNTimeIntervalNotificationTrigger(timeInterval: 60,
repeats: true)
let request = UNNotificationRequest(identifier: "testNotification",
content: notificationContent,
trigger: trigger)
userNotificationCenter.add(request) { (error) in
if let error = error {
print("Notification Error: ", error)
}
}
它运行良好,但我无法停止它,即使我的应用程序被终止,它也会继续发送通知。
在这种情况下,阻止 UNUserNotificationCenter 发送通知的最佳方法是什么?
【问题讨论】:
标签: ios swift unusernotificationcenter