Tom
Tom

Reputation: 175

Error : Stopped workout session cannot be restarted

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

Upvotes: 2

Views: 608

Answers (1)

Allan
Allan

Reputation: 7363

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.

Upvotes: 3

Related Questions