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?