简体   繁体   English

WatchOS:每当启动 NRC 或 Runtastic 等第二个应用程序时,HKWorkoutSession 就会结束

[英]WatchOS: HKWorkoutSession ends whenever a second app like NRC or Runtastic is started

I am testing the SpeedySloth demo app from Apple: https://developer.apple.com/documentation/healthkit/workouts_and_activity_rings/speedysloth_creating_a_workout我正在测试 Apple 的 SpeedySloth 演示应用程序: https://developer.apple.com/documentation/healthkit/workouts_and_activity_rings/speedysloth_creating_a_workout

Well, this ends here, whenever a second app starts:好吧,这到此结束,每当第二个应用程序启动时:

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

The delegate is directly called with toState =.ended when I press the "Start" Button in Nike Running Club.当我在 Nike Running Club 中按下“开始”按钮时,直接使用 toState =.ended 调用代表。 I assume, that there is only one workout possible at one time, BUT I can use Adidas Running along with NRC, so, it must be somehow possible.我假设一次只能进行一种锻炼,但是我可以将 Adidas Running 与 NRC 一起使用,因此,它一定是可能的。

The documentation for HKWorkoutSession states that only one can be run at a time. HKWorkoutSession 的文档说明一次只能运行一个。

Apple Watch runs one workout session at a time. Apple Watch 一次运行一项锻炼 session。 If a second workout starts while your workout is running, your HKWorkoutSessionDelegate object receives an HKError.Code.errorAnotherWorkoutSessionStarted error, and your session ends.如果在锻炼期间开始第二次锻炼,您的 HKWorkoutSessionDelegate object 会收到 HKError.Code.errorAnotherWorkoutSessionStarted 错误,并且您的 session 会结束。

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

Before the Apple Watch came out several Apps allowed users to measure a run or walk session by using the CoreMotion APIs.在 Apple Watch 推出之前,一些应用程序允许用户使用 CoreMotion API 测量跑步或步行 session。 I suspect one of the Apps you mention may fall back to this if a Workout Session is already running.如果 Workout Session 已经在运行,我怀疑您提到的其中一个应用程序可能会退回到此。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM