HKWorkoutSession 没有将应用程序放在 Apple Watch 前面 [英] HKWorkoutSession isn't keeping app at front of Apple Watch
问题描述
有人表示,运行 HKWorkoutSession 的应用程序将比其他 watchOS 2 应用程序具有特殊权限,因此当用户查看他们的 Apple Watch 时,它会转到显示正在锻炼的视图,而不是表盘.
It has been stated that an app running a HKWorkoutSession will have special privileges over other watchOS 2 apps, so when a user looks at their Apple Watch, it will go to the view showing running a workout rather than the watch face.
目前,在我的设备和模拟器上,情况并非如此.如果我开始 HKWorkoutSession,然后离开 5 分钟,然后与 Apple Watch 或 Watch Simulator 交互,它会显示表盘.
Currently, on both my device and simulator, this is not the case. If I start a HKWorkoutSession and then leave for 5 minutes and then interact with either the Apple Watch, or the Watch Simulator, it presents the watch face.
如果我然后打开我的应用程序,它似乎已被冻结,而不是终止(我认为其他应用程序会发生这种情况).当我需要在我的 query.updateHandler 中接收响应时,UI 会更新.此外,如果我将其设置为每次我的 query.updateHandler 收到新的 HKQuantitySample 时都提供触觉反馈,它就会这样做,因此应用程序必须以某种形式在后台运行.
If I then open my app, it appears to have been frozen, rather than terminated (which is what I imagine happens to other apps). As the UI will update when I need receive a response in my query.updateHandler. Also if I set it to provide haptic feedback every time my query.updateHandler receives a new HKQuantitySample it will do so, so the app must be running in the background in some form.
有没有其他人注意到这种行为,我是否做错了什么,或者期待我不应该做的事情?
Has anyone else noticed this behaviour, and am I doing anything wrong, or expecting something I shouldn't?
这是我如何开始我的 HKWorkoutSession:
Here is how I start my HKWorkoutSession:
self.workoutSession = HKWorkoutSession(activityType: HKWorkoutActivityType.Other, locationType: HKWorkoutSessionLocationType.Indoor)
self.healthStore.startWorkoutSession(self.workoutSession) {
success, error in
if error != nil {
print("startWorkoutSession \(error)\n")
self.printLabel.setText("startWorkoutSession \(error)")
self.printLabel.setTextColor(UIColor.redColor())
}
推荐答案
我们也看到了这一点,目前我们已经确保配置了打开上一个活动".
We're seeing that too, for the moment we've made sure 'opens last activity' is configured.
当 UI 处于活动状态时,我们会启动一个 dispatch_timer 以 1 秒为间隔请求和处理数据.
When the UI is active we start a dispatch_timer to request and process data in 1 second intervals.
确保您使用 NSUserProcessInfo 方法进行任何重要的处理,并在您不再活动时暂停 dispatch_timers.否则你会崩溃.
Make sure you do any significant processing using the NSUserProcessInfo method though and pause the dispatch_timers whenever you are no longer active. You'll get crashes otherwise.
这篇关于HKWorkoutSession 没有将应用程序放在 Apple Watch 前面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!