ios - Apple Watch 配套应用本地通知延迟?

标签 ios swift watchos

我有一个 Apple Watch 应用程序作为 iPhone 应用程序的配套应用程序。 Apple Watch App 上的本地通知有延迟。我安排了 10 秒后触发本地通知。当我按下 watch 上创建通知的按钮并退出应用程序时,显示通知的时间不是 10 秒,而是大约 23 秒。

我使用相同的本地通知代码创建了一个测试独立/独立的 Apple Watch 应用,在这种情况下,本地通知会在正确的时间触发。

我使用的是 watchOS 8.1。这是 Apple Watch 的新功能还是 bug?因为在 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")
      }
    }

最佳答案

这里有一个反馈: https://developer.apple.com/forums/thread/696280

This is correct behaviour.

If you have both a phone and watch app installed we’ll try to coordinate between phone and watch notifications if the phone is unlocked. If the app developer doesn’t send a notification on the phone the watch will timeout after 13 seconds and alert anyway.

The best solution to this would be to send the same notification on both devices ensuring the UNNotificationRequest.identifier matches on a per-instance basis.

This will let us alert and deduce correctly.

如果 watch 应用发送本地通知,我会提前 13 秒发送通知。这样通知就显得准时了

希望 future 有更好的解决方案

关于ios - Apple Watch 配套应用本地通知延迟?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/70311816/

相关文章:

加载时 iOS 8 Today 小部件不显示

ios - 重新加载 viewDidAppear 以便它将用作 ViewDidLoad

ios - 不断询问 iTunes Sandbox 帐户凭据

ios - 当我的应用程序被杀死时不要收到通知

ios - UITextField 上的清除按钮

Swiftui - Apple Watch 上的 Metal 渲染

swift - apple watch app 是否有可能知道它是使用 Complication 接口(interface)启动的?

ios - 使用 NSLayoutConstraints 将 View 放置在其 super View 的边界之外

ios - 如何使用 Swift 在 iOS 中制作对角线 UITableView?

ios - 如何在 WatchOS 的基于页面的界面中显示警报?