swift - 为什么 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 秒后正确显示!
解决方案
我在手表上生成的本地通知中也注意到了这一点。我已经生成了从 30 秒到 3 分钟(以 30 秒为增量)的通知,并且它们始终晚了大约 13 秒。在 watchOS 6 之前,他们没有迟到。
推荐阅读
- julia - Julia 1.1.1 - 绝对全局变量
- javascript - 如何在 Highcharts 中添加自定义图标作为标记
- python - 我有一个非功能性的 lambda。我如何在本地运行它以找出问题所在?
- arrays - 使用唯一的 Int 仅显示 SwiftUI 中的数组选择
- sql - 用于除法和乘法的 SQL Server 计算列公式
- reactjs - WebChat 中的 BotFramework v4 在消息后显示机器人的名称和用户名
- javascript - Vue,Vuetify 没有正确初始化
- python - 带有 attrs 的 PyTorch 模块无法获取参数列表
- python-3.x - 如何在保持索引到位的同时将新列分配给 Pandas 数据框?
- c# - 如何通过 C# Selenium 错误页面?