7

I'd like to access the live heart rate at in my apple watchOS app. In the keynote they emphasized that developers can access the live data now. But I can't find anything about it in the documentation.

Does anyone have a hint for me?

Jonathan
  • 443
  • 3
  • 9
  • Can you provide the code you've started with or where you're stuck specifically? – JP Silvashy Jul 03 '16 at 16:23
  • the thing is I dont know, how to get started. I try to understand of live heart rate in watchOS 3. But: I've found this github project, looking in to it right now https://github.com/coolioxlr/watchOS-3-heartrate – Jonathan Jul 03 '16 at 16:28
  • 3
    Being able to access heart rate is not new in watchOS 3. What did change is that workout apps are now able to stay running while the Apple Watch screen is off, meaning that heart rate samples can be processed live during a workout session, even when the user is not directly interacting with the app. – Allan Jul 03 '16 at 19:12
  • 1
    Have you created other watchOS apps? I think you should give it an honest effort before asking for help. – JP Silvashy Jul 03 '16 at 22:22

1 Answers1

11

The GitHub project you mention (github.com/coolioxlr/watchOS-3-heartrate) in your comment is a really good place to start.

In order to get the heart rate data, your app is going to first need to request read access to HealthKit for the heart rate data. Unfortunately, you are unable to get the data directly from the sensor so you will have to query for it from HealthKit. To do so, you will need to create a streaming query. If you want it "live" or with a high sampling rate, you should create a workout session. Just remember to end the workout session (particularly while testing) because otherwise the workout continues (you will see the little green workout icon at the top of your watch face) and your watch will burn through the battery. If that happens open up the Apple work out app on your watch, start a work out, and then end it, as starting a new workout session ends an old one.

I hope this helps you get started :)

immadbananas
  • 309
  • 2
  • 6
  • thank you for the advice! I actually started with it and got most of the basic stuff figured out. Now I am having trouble with playing audio feedback. But that is a [different story](http://stackoverflow.com/questions/43190240/how-to-build-a-workout-app-on-watchos-with-audio-feedback). – Jonathan Apr 03 '17 at 16:59