【发布时间】:2019-11-29 18:07:12
【问题描述】:
我有一个函数,想在该函数执行时发送本地通知。现在我一直在使用时间间隔通知触发器并将间隔设置为 0.1 秒,但这感觉不是立即发送通知的正确方法,因为它仍然有 0.1 秒的延迟,即使它几乎不引人注意.
我的问题是,有没有一种方法可以立即发送通知,就像没有任何延迟一样?我一直在寻找这个问题的解决方案,但没有找到任何解决方案,希望你们能提供帮助。谢谢。
func didUpdateSettings() {
//other code...
let content = UNMutableNotificationContent()
content.title = "Notification title"
content.subtitle = "Notification subtitle"
content.body = "Notification body"
content.sound = UNNotificationSound.default
let trigger = UNTimeIntervalNotificationTrigger(timeInterval: 0.1, repeats: false)
let request = UNNotificationRequest(identifier: "timerDone", content: content, trigger: trigger)
UNUserNotificationCenter.current().add(request, withCompletionHandler: nil)
}
【问题讨论】:
标签: swift iphone notifications ios12