Error : Stopped workout session cannot be restarted

倖福魔咒の 提交于 2021-01-28 02:05:35

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!