问题描述
我可以启动和停止 HealthKit
锻炼会话.但是,当我尝试停止第一次锻炼后再尝试第二次锻炼时,我会收到错误消息:
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:
如何在不关闭并重新启动应用程序的情况下启动下一个锻炼会话
(在第一个会话停止之后)?我正在使用 Xcode 7.2 , IOS9.2 和 Watch OS 2.1
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.2and Watch OS 2.1
从InterfaceController停止:
Stopping from InterfaceController:
func startWorkout() {
myExtensionConnectivity.startSession()
myExtensionHealthKitManager.startWorkout()
myExtensionConnectivity.sendStartUpdatingCommand()
}
func stopWorkout() {
myExtensionConnectivity.sendStopUpdatingCommand()
myExtensionHealthKitManager.endWorkout()
myExtensionConnectivity.stopSession()
}
从HealthkitManager:
From HealthkitManager:
func endWorkout() {
healthStore.endWorkoutSession(workoutSession)
}
func startWorkout() {
healthStore.startWorkoutSession(workoutSession)
}
推荐答案
在开始第二次锻炼之前,您需要创建一个新的HKWorkoutSession实例.如错误消息所述,您可能无法重新启动已停止的会话.
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.
这篇关于错误:已停止的锻炼会话无法重新启动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!