问题
I can start and stop a HealthKit
workout session. But when I try to start a second workout after my first has stopped, I get the error:
"workOutSession Error : Stopped workout session cannot be restarted"
How do I start the next workout session
(after the first has been stopped) without closing down and restarting the app? I am using Xcode 7.2, IOS9.2
and Watch OS 2.1
Stopping from InterfaceController:
func startWorkout() {
myExtensionConnectivity.startSession()
myExtensionHealthKitManager.startWorkout()
myExtensionConnectivity.sendStartUpdatingCommand()
}
func stopWorkout() {
myExtensionConnectivity.sendStopUpdatingCommand()
myExtensionHealthKitManager.endWorkout()
myExtensionConnectivity.stopSession()
}
From HealthkitManager:
func endWorkout() {
healthStore.endWorkoutSession(workoutSession)
}
func startWorkout() {
healthStore.startWorkoutSession(workoutSession)
}
回答1:
You need to create a new HKWorkoutSession instance before starting the second workout. As the error message states, you may not re-start a stopped session.
来源:https://stackoverflow.com/questions/34373387/error-stopped-workout-session-cannot-be-restarted