iOS get heart rate from Apple Watch in near real time iOS get heart rate from Apple Watch in near real time swift swift

iOS get heart rate from Apple Watch in near real time


UPDATE

As noticed by @BootMaker, Apple made background mode available for HKWorkout apps in WatchOS 3, so it's working now. You have to run a HKWorkoutSession and this will keep your heartrate delivery in real time even when the app is in the background (dark screen on watch)

The closest you are going to be is while the watch app is open.

Why I'm stating this?

  1. There are two HealthKit's Database (one at the iPhone and another at the Apple Watch). When they sync is arbitrary and decided only by the O.S.

  2. The closest you are going to be to real time is when you don't have any password locking your screen in iPhone or Apple Watch. Either way, there's no guarantee that the sync will happen every time a new measure is added to Apple Watch's HealthKit

  3. The only way to force the Heart rate sensor into working in real time is via workouts or observer while your Apple Watch app is in FOREGROUND.

  4. Background delivery is NOT available for Apple Watch apps.

  5. Watch OS 2 request the sensor to measure automatically (in background) every 10 minutes minimum.

There's no other workaround, if you need real time for longer periods, or while the user is not using your app, you will need to use an specialized wearable.


If anyone still need to get heart rate or other data in real time. Use this solution:

  1. Develop an apple watch app/extention
  2. In watch app, using HKHealthStore, HKWorkoutConfiguration, HKWorkoutSession, HKLiveWorkoutBuilder to create an Workout. After create workout, your watch app will get heart rate in real time.
  3. Using watch kit connection with WCSession to send data to iPhone app.
  4. Enable background mode both in apple watch and iPhone.

I tested, even app terminated, we can still get heart rate (I used Local notification for posting heart rate data for debugging)