簡體   English   中英

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 Running Club 中按下“開始”按鈕時,直接使用 toState =.ended 調用代表。 我假設一次只能進行一種鍛煉,但是我可以將 Adidas Running 與 NRC 一起使用,因此,它一定是可能的。

HKWorkoutSession 的文檔說明一次只能運行一個。

Apple Watch 一次運行一項鍛煉 session。 如果在鍛煉期間開始第二次鍛煉,您的 HKWorkoutSessionDelegate object 會收到 HKError.Code.errorAnotherWorkoutSessionStarted 錯誤,並且您的 session 會結束。

請參閱https://developer.apple.com/documentation/healthkit/hkworkoutsession

在 Apple Watch 推出之前,一些應用程序允許用戶使用 CoreMotion API 測量跑步或步行 session。 如果 Workout Session 已經在運行,我懷疑您提到的其中一個應用程序可能會退回到此。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM