Apple Watch : Total calories and duration of workout is inaccurate (low)

Viewed 109

I'm currently having an issue tracking active calories and the total duration of workouts on the Apple Watch. Sometimes it is correct and sometimes they are relatively low. Workout generally lasts 50~70 mins, but it logs only 16 mins, 21 mins, or some random number on Apple Watch and in Apple Health. Same for calories.

iPhone workout app:

    func startWatchApp(...) {
        getActiveWCSession { wcSession in
            if wcSession.activationState == .activated && wcSession.isWatchAppInstalled {
                
                let configuration = HKWorkoutConfiguration()
                configuration.activityType = .highIntensityIntervalTraining
                configuration.locationType = .indoor
                
                self.healthStore.startWatchApp(with: configuration, completion: { (success, error) in
                    print("⌚️ started watch app with error: \(error?.localizedDescription ?? "No error")")
                })
            } else{
                print("⌚️ watch not active or not installed")
            }
        }
    }

Watch App:

class ExtensionDelegate: NSObject, WKExtensionDelegate {
    func handle(_ workoutConfiguration: HKWorkoutConfiguration) {
        WorkoutManager.shared.startWorkout(with: workoutConfiguration)
    }
}

class WorkoutManager: NSObject, ObservableObject {
    func startWorkout(with configuration: HKWorkoutConfiguration) {
        do {
            let session = try HKWorkoutSession(healthStore: healthStore, configuration: configuration)
            
            setupWorkoutWith(session: session)
        } catch {
            print("Error initializing HealthKit workout session. \(error.localizedDescription)")
            return
        }
    }

    func setupWorkoutWith(session: HKWorkoutSession) {
        self.session = session
        
        let configuration = session.workoutConfiguration
        
        builder = session.associatedWorkoutBuilder()
        builder?.dataSource = HKLiveWorkoutDataSource(
            healthStore: healthStore,
            workoutConfiguration: configuration
        )
        
        session.delegate = self
        builder?.delegate = self
        
        builder?.shouldCollectWorkoutEvents = true
        
        // Start the workout session and begin data collection
        // if session already started(recovered)
        let startDate = session.startDate ?? Date()
        if session.startDate == nil {
            session.startActivity(with: startDate)
        }
        
        builder?.beginCollection(withStart: startDate, completion: { success, error in
            if let error = error {
                print("Workout builder begin collection error: \(error.localizedDescription)")
            }
        })
        
    }


    func endSession() {
        session?.end()
        
        builder?.endCollection(withEnd: Date(), completion: { success, error in
            self.builder?.finishWorkout(completion: { workout, error in
                DispatchQueue.main.async {
                    if let error = error {
                        print("save workout error: \(error.localizedDescription)")
                    } else {
                        self.workout = workout
                    }
                }
            })
        })
    }

Is there anything I missed or should consider when building workout apps?

1 Answers

Even when using Apple's fitness tracking App you will see these inaccuracies.

there are two main reasons for this:

  1. your watch needs calibrating. you will find that a lot of Apple watch users are facing this problem and it resolved after calibrating their watch. How to calibrate an Apple Watch for accurate fitness tracking
  2. anytime sensor readings are unavailable for any reason such as (battery saving mode or loose watch band)
Related