当父 iPhone 应用程序在后台运行时,如何使用 startWatchApp()?

问题描述 投票:0回答:2

假设父 iPhone 应用程序在后台运行,如何使用 Swift 打开 Apple Watch 应用程序而不会出现以下错误?

Error Domain=com.apple.healthkit Code=550 "Cannot start watch app when phone app is in background" UserInfo={NSLocalizedDescription=Cannot start watch app when phone app is in background}
ios swift apple-watch healthkit watchos
2个回答
2
投票

你不能。错误消息清楚地表明 API 打算阻止您执行此操作。


0
投票

当配套的 iOS 应用程序处于非活动状态时,您无法从其启动,这是 Apple 严格禁止的。但您可以检查其他选项,例如在 WatchOS 应用程序中安排 ExtendedRunTimeSession。您可以通知伴侣将触发时间安排在 36 小时以内。通过这种方式,您可以调整您的功能。这只是另一种选择,取决于您的用例是否可行。

请注意,当 WatchOS 应用程序处于活动状态时,此计划也应该发生。但一旦安排好,即使 WatchOS 应用程序处于非活动状态或在后台,它也可以在那时触发。

请检查以下链接以获取更多信息:- https://developer.apple.com/documentation/watchkit/using_extended_runtime_sessions

© www.soinside.com 2019 - 2024. All rights reserved.