WatchOS:HKWorkoutSession在NRC或Runtastic等第二个应用程序启动时结束



我正在测试苹果的SpeedyCloth演示应用程序:https://developer.apple.com/documentation/healthkit/workouts_and_activity_rings/speedysloth_creating_a_workout

好吧,这就结束了,每当第二个应用程序启动时:

// MARK: - HKWorkoutSessionDelegate
extension WorkoutManager: HKWorkoutSessionDelegate {
func workoutSession(_ workoutSession: HKWorkoutSession, didChangeTo toState: HKWorkoutSessionState,
from fromState: HKWorkoutSessionState, date: Date) {
// Wait for the session to transition states before ending the builder.
/// - Tag: SaveWorkout
if toState == .ended {
print("The workout has now ended.")
builder.endCollection(withEnd: Date()) { (success, error) in
self.builder.finishWorkout { (workout, error) in
// Optionally display a workout summary to the user.
self.resetWorkout()
}
}
}
}

当我按下"键时,直接调用toState=.endd的委托;启动";Nike Running Club中的按钮。我认为,一次只能进行一次锻炼,但我可以使用阿迪达斯跑步和NRC,所以,这一定是可能的。

HKWorkoutSession的文档规定一次只能运行一个。

Apple Watch一次只进行一次训练。如果第二次训练在你的训练进行时开始,你的HKWorkoutSessionDelegate对象会收到一个HKError.Code.errorOtherWorkoutSessionStarted错误,你的训练结束。

请参阅https://developer.apple.com/documentation/healthkit/hkworkoutsession

在Apple Watch问世之前,有几个应用程序允许用户通过使用CoreMotion API来测量跑步或步行会话。我怀疑,如果训练课程已经在运行,你提到的其中一个应用程序可能会回到这个状态。

最新更新