【发布时间】:2021-12-11 00:41:53
【问题描述】:
我有一个 Apple Watch 应用程序作为 iPhone 应用程序的配套应用程序。 Apple Watch App 上的本地通知延迟。我安排在 10 秒后触发本地通知。当我按下手表上创建通知的按钮并退出应用程序时,显示通知不需要 10 秒,而是大约 23 秒。
我创建了一个具有相同本地通知代码的独立测试/独立 Apple Watch 应用,在这种情况下,本地通知会在正确的时间触发。
我使用的是 watchOS 8.1。这是 Apple Watch 上的新功能还是错误?因为在 iPhone 上它可以毫无延迟地工作。提前谢谢你:)
// Configure the notification's payload.
let content = UNMutableNotificationContent()
content.title = "Drink some milk!"
content.subtitle = "you have 10 sec"
content.sound = .default
content.categoryIdentifier = "myCategory"
let category = UNNotificationCategory(identifier: "myCategory", actions: [], intentIdentifiers: [], options: [])
UNUserNotificationCenter.current().setNotificationCategories([category])
let trigger = UNTimeIntervalNotificationTrigger(timeInterval: 10, repeats: false)
let request = UNNotificationRequest(identifier: "milk", content: content, trigger: trigger)
UNUserNotificationCenter.current().add(request) { (error) in
if let error = error{
print(error.localizedDescription)
}else{
print("scheduled successfully")
}
}
【问题讨论】:
-
watchos 8.3 的同样问题