WatchOS:每当启动第二个应用程序(如 NRC 或 Runtastic)时,HKWorkoutSession 就会结束
WatchOS: HKWorkoutSession ends whenever a second app like NRC or Runtastic is started
我正在测试 Apple 的 SpeedySloth 演示应用程序: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()
}
}
}
}
当我在 Nike 运行 Club 中按下“开始”按钮时,使用 toState = .ended 直接调用委托。我假设,一次只能进行一种锻炼,但我可以将 Adidas 运行 与 NRC 一起使用,因此,它一定是可行的。
HKWorkoutSession 的文档指出一次只能 运行。
Apple Watch runs one workout session at a time. If a second workout starts while your workout is running, your HKWorkoutSessionDelegate object receives an HKError.Code.errorAnotherWorkoutSessionStarted error, and your session ends.
见https://developer.apple.com/documentation/healthkit/hkworkoutsession
在 Apple Watch 推出之前,有几个应用程序允许用户使用 CoreMotion API 测量 运行 或步行会话。我怀疑如果锻炼会话已经 运行ning.
,你提到的其中一个应用程序可能会退回到这个
我正在测试 Apple 的 SpeedySloth 演示应用程序: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()
}
}
}
}
当我在 Nike 运行 Club 中按下“开始”按钮时,使用 toState = .ended 直接调用委托。我假设,一次只能进行一种锻炼,但我可以将 Adidas 运行 与 NRC 一起使用,因此,它一定是可行的。
HKWorkoutSession 的文档指出一次只能 运行。
Apple Watch runs one workout session at a time. If a second workout starts while your workout is running, your HKWorkoutSessionDelegate object receives an HKError.Code.errorAnotherWorkoutSessionStarted error, and your session ends.
见https://developer.apple.com/documentation/healthkit/hkworkoutsession
在 Apple Watch 推出之前,有几个应用程序允许用户使用 CoreMotion API 测量 运行 或步行会话。我怀疑如果锻炼会话已经 运行ning.
,你提到的其中一个应用程序可能会退回到这个