Jason Krowl
Jason Krowl

Reputation: 114

How to access elevation gain, cadence and running pace from HealthKit running workout?

I need to access elevation gain, cadence and running pace (not average but for like each kilometre) workouts are from AppleWatch.

Is there any way how to get access to those data. Currently I have access for the workout's duration, distance covered ... is there any metadata for these? I can not find anything in Apple's documentation for HealthKit.

I have figured now that I have to do queries for stepCount and distanceCovered to get the pace and cadence, but still can not get access to elevation gain data.

Upvotes: 2

Views: 1692

Answers (1)

Gary Joy
Gary Joy

Reputation: 103

If workout is your HKWorkout object then you can do:

if let workoutMetadata = workout.metadata {
    if let workoutElevation = workoutMetadata["HKElevationAscended"] as? HKQuantity {
        print("Elevation = \(workoutElevation.doubleValue(for: HKUnit.meter()))m")
    }
}

It does seem a bit strange that some values are not available as properties. I guess it's because they only apply to limited number of workout types.

Upvotes: 3

Related Questions