首页 > 解决方案 > 为什么 Apple Watch 的本地通知会延迟?

问题描述

我为 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 秒后正确显示!

标签: swiftuilocalnotificationapple-watchwatchos-6

解决方案


我在手表上生成的本地通知中也注意到了这一点。我已经生成了从 30 秒到 3 分钟(以 30 秒为增量)的通知,并且它们始终晚了大约 13 秒。在 watchOS 6 之前,他们没有迟到。


推荐阅读