Having trouble starting a workout

I am having trouble starting a workout in watchOS 3 beta 1. I have requested authorization to all of my healthkit types and I have added the new iOS 10 plist info items (Privacy - Health Update Usage Description & Privacy - Health Share Usage Description). Here is what I am calling to start my workout:


    @IBAction func startWorkout() {
        let workoutConfiguration = HKWorkoutConfiguration()
        workoutConfiguration.activityType = .traditionalStrengthTraining
        workoutConfiguration.locationType = .indoor
  
        do {
            try self.workoutSession = HKWorkoutSession(configuration: workoutConfiguration)
            guard let workoutSession = self.workoutSession else { return }
            workoutSession.delegate = self
            self.healthStore.start(workoutSession)
        } catch {
            WKInterfaceDevice.current().play(.failure)
        }
    }

    func workoutSession(_ workoutSession: HKWorkoutSession, didFailWithError error: NSError) {
        WKInterfaceDevice.current().play(.failure)
    }


The delegate method workoutSession:didFailWithError end up getting called with the following error:


Error Domain=com.apple.healthkit Code=3 "Cannot start workout session while process is in background." UserInfo={NSLocalizedDescription=Cannot start workout session while process is in background.}


The app is in the foreground, and the workout was started directly from a UI button tap (I verified it is being called on the main thread). Does anyone have any ideas about what might be causing this issue?

Answered by lehn0058 in 146114022

Looks like this is only a problem when using the Apple Watch simulator. The same code works fine for me with my physical Apple Watch.

Note, this issue happens whether or not the new watchOS 3 background mode "workout processing" is enabled or not.

Accepted Answer

Looks like this is only a problem when using the Apple Watch simulator. The same code works fine for me with my physical Apple Watch.

Having trouble starting a workout
 
 
Q