HKWorkoutSession isn't keeping app at front of Apple Watch

人走茶凉 提交于 2019-12-03 10:05:02

问题


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.

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.

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?

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())
            }

回答1:


We're seeing that too, for the moment we've made sure 'opens last activity' is configured.

When the UI is active we start a dispatch_timer to request and process data in 1 second intervals.

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.



来源:https://stackoverflow.com/questions/31224611/hkworkoutsession-isnt-keeping-app-at-front-of-apple-watch

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!