Search code examples
watchkitapple-watchhealthkitwatchos-2

HKWorkoutSession isn't keeping app at front of 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.

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

Solution

  • 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.