iosswifthealthkithkhealthstore

How to add total distance to HKLiveWorkouts


I am using the new HKLiveWorkoutBuilder to create a Healthkit Workout. All is well except that I can't figure out how to give the workout a total distance. I add the distance sample which works (although it shows the unit twice in Health e.g. 200 mi mi) but when querying the workout later it does not have a total distance, and even in the workout builders finishWorkout() function the workout does not have a total distance. Does anyone know how I can get total distance on Live Workouts?


Solution

  • Seems like setting the activity type on the HKWorkoutConfiguration() is the answer. I was using "other" as the activity type and for whatever reason the resulting HKWorkout does not have a total distance. I switched the activity type to walking and it works fine.