![](/img/trans.png)
[英]watchOS, WCSession activationDidCompleteWith "activated", yet is not reachable
[英]How to make WCSession reachable when the watchOS app is running in background with HKWorkoutSession
我的 watchOS 应用程序使用锻炼 API 以便在应用程序进入后台时保持运行。 问题是当应用程序处于后台时WCSession
变得无法访问。 但是,我能够运行我的代码,并且在某些情况下,它需要向 iPhone 对应应用程序发送消息。
该应用程序的细节要求用户不必与之交互 - 如果超时,手表应用程序应自动将消息发送到手机。
这有可能实现吗? 谢谢。
我相信handle(_ backgroundTasks: Set<WKRefreshBackgroundTask>)
方法就是你要找的。 文档链接
在没有看到您的代码的情况下,我无法确定您当前的进度是什么,但我已使用此方法在用户位置更改时在后台更新 watchOS 并发症。
func handle(_ backgroundTasks: Set<WKRefreshBackgroundTask>) {
for task in backgroundTasks {
if WKExtension.shared().applicationState == .background {
// Do your background work here.
if let watchComplication = task as? WKWatchConnectivityRefreshBackgroundTask {
pendingConnectivityTasks.append(watchComplication)
}
}
task.setTaskCompletedWithSnapshot(true)
}
completePendingConnectivityTasksIfNeeded()
}
作为附带说明,如果您的应用程序不是实际的锻炼应用程序,我将添加,它会在应用程序审查期间因使用 HealthKit 锻炼 session 而被拒绝。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.