Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Apple HealthKit - Do workouts have associated heart rate data?

Tags:

ios

healthkit

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!

like image 254
Hester Avatar asked Jan 09 '17 08:01

Hester


People also ask

Does Apple Watch track exercise by heart rate?

Heart rate is one of many factors that Apple Watch uses to measure your activity and exercise. Depending on your workout, it selects the most appropriate inputs for that activity. For example, when you're running indoors, it also uses the accelerometer.

What is a HealthKit workout?

A workout is a container for these types of information, taken as a collection of samples. A given workout might contain heart rate samples, distance samples and an activity type to categorize them. Continuing from the previous HealthKit tutorial, you're going to track a special kind of workout: Prancercise.

Can iPhone detect heart rate?

* Place the tip of your index finger on the iPhone's camera, and in a couple of seconds, your pulse will be shown! * Instant Heart Rate detects a color change in your finger tip each time your heart beats and uses an advanced algorithm to show you your heart rate.


1 Answers

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.

like image 180
Allan Avatar answered Oct 05 '22 11:10

Allan