Search code examples
ioshealthkit

Apple HealthKit - Do workouts have associated heart rate data?


I'm writing my own fitness app that I hope to bridge the void between the Fitbit app and Apple Health (I finally ditched my Blaze for an Apple Watch). So far I am able to retrieve the workouts for the last 7 days but I want to display a heart rate graph (like Fitbit does) for the workout when you click to view it. Does the workout contain the heart rate samples recorded during the workout or do I need to query the heart rate for start and end time matching the workout separately? I've played about a bit and tried to find the answer in the documentation but I'm finding it a bit difficult to understand so sorry if I've missed something obvious!


Solution

  • The Workout app on Apple Watch does not associate heart rate samples with its HKWorkout instances, so querying for heart rate samples using +[HKQuery predicateForObjectsFromWorkout:] will not return any results. Instead, you should query for heart rate samples using a date range predicate spanning the duration of the workout.