【发布时间】:2020-02-05 13:37:09
【问题描述】:
我为 Apple Watch 创建了一个应用程序,并为 iPhone 创建了一个配套应用程序。这两个应用在两台设备上测试本地通知。
但由于我更新到 iOS 13.1.2 和 WatchOS 6.0.1,Apple 上的本地通知延迟:当我按下手表上创建通知的按钮并退出应用程序时,不需要 5秒显示通知,但大约 20 秒...当我将代码更改为 3 秒时,显示需要 16 秒。
这是 Apple Watch 的新功能还是错误?因为在 iPhone 上它可以毫无延迟地工作。
提前谢谢你:)
// Configure the notification's payload.
let content = UNMutableNotificationContent()
content.title = NSString.localizedUserNotificationString(forKey: "Hello!", arguments: nil)
content.body = NSString.localizedUserNotificationString(forKey: "Hello_message_body", arguments: nil)
content.sound = UNNotificationSound.default
// Deliver the notification in five seconds.
let trigger = UNTimeIntervalNotificationTrigger(timeInterval: 5, repeats: false)
let request = UNNotificationRequest(identifier: "FiveSecond", content: content, trigger: trigger) // Schedule the notification.
let center = UNUserNotificationCenter.current()
center.add(request) { (error : Error?) in
if let theError = error {
// Handle any errors
}
}
编辑:
我还注意到这种奇怪的行为:当我在 iPhone 上创建通知时,按下按钮然后将手机置于待机状态,以便将通知传送到 Apple Watch,通知在手表上 5 秒后正确显示!
【问题讨论】:
-
发送更长的通知,例如5 分钟或 30 分钟按时交付?我可以想象这是一个解决问题,例如通知循环仅每隔几秒运行一次,或者在您关闭应用程序时故意阻止应用程序触发通知 - 那有什么用例?
-
我正在使用 WatchConnectivity 让 Apple Watch 创建通知,在 didReceiveUserInfo 中我放了代码。此外,我正在使用扩展运行时会话来使应用程序在后台运行。但是我没有创建通知,而是在手表上创建了振动,没有延迟......
标签: swift uilocalnotification apple-watch watchos-6