Watch Os 2.0 Beta: Access Heart Beat Rate

Watch os 2.0 beta: access heart beat rate

Apple isn't technically giving developers access to the heart rate sensors in watchOS 2.0. What they are doing is providing direct access to heart rate data recorded by the sensor in HealthKit. To do this and get data in near-real time, there are two main things you need to do. First, you need to tell the watch that you are starting a workout (lets say you are running):

// Create a new workout session
self.workoutSession = HKWorkoutSession(activityType: .Running, locationType: .Indoor)
self.workoutSession!.delegate = self;

// Start the workout session
self.healthStore.startWorkoutSession(self.workoutSession!)

Then, you can start a streaming query from HKHealthKit to give you updates as HealthKit receives them:

// This is the type you want updates on. It can be any health kit type, including heart rate.
let distanceType = HKObjectType.quantityTypeForIdentifier(HKQuantityTypeIdentifierDistanceWalkingRunning)

// Match samples with a start date after the workout start
let predicate = HKQuery.predicateForSamplesWithStartDate(workoutStartDate, endDate: nil, options: .None)

let distanceQuery = HKAnchoredObjectQuery(type: distanceType!, predicate: predicate, anchor: 0, limit: 0) { (query, samples, deletedObjects, anchor, error) -> Void in
// Handle when the query first returns results
// TODO: do whatever you want with samples (note you are not on the main thread)
}

// This is called each time a new value is entered into HealthKit (samples may be batched together for efficiency)
distanceQuery.updateHandler = { (query, samples, deletedObjects, anchor, error) -> Void in
// Handle update notifications after the query has initially run
// TODO: do whatever you want with samples (note you are not on the main thread)
}

// Start the query
self.healthStore.executeQuery(distanceQuery)

This is all described in full detail in the demo at the end of the video What's New in HealthKit - WWDC 2015

Is heart rate raw data available for developers via WatchKit?

Heart Rate Raw Data information is now available in Watchkit for watchOS 2.0.

WatchOS 2 includes many enhancements to other existing frameworks such as HealthKit, enabling access to the health sensors that access heart rate and health information in real-time.

You could check this information in the following session which is total 30 minutes presentation.If you do not want to watch entire session, then you directly jump to Healthkit API features which is in between 25-28 min:

WatchKit for watchOS 2.0 Session in WWDC 2015

Here is the source code implementation link

Heart Rate data on apple Watch

There is no direct way to access any sensors on the Apple Watch. You will have to rely on access from HealthKit.

An Apple evangelist said this

It is not possible to create a heart monitor app at this time. The
data isn't guaranteed to be sent to iPhone in real-time, so you won't
be able to determine what's going on in any timely fashion.

See https://devforums.apple.com/message/1098855#1098855

Track beat to beat heart rate apple watch through HRV

After filing an technical support incident (TSI) at Apple about this, they said that it's currently not possible to do this.

Thank you for contacting Apple Developer Technical Support (DTS). Our engineers have reviewed your request and have concluded that there is no supported way to achieve the desired functionality given the currently shipping system configurations.

If you would like for Apple to consider adding support for such features in the future, please submit an enhancement request via the Bug Reporter tool at https://developer.apple.com/bug-reporting/.

If you'd like to see this functionality, please file a bug report!

Problems returning heart rate values using `HKAnchoredObjectQuery` on Series 5 Watch and Watch OS6

Strange but it turns out I had Workout Power Saving Mode set to on in the Watch App's settings. Unless I set by accident it was set to on when I installed Watch OS 6? After turning it off the heart rate queries are returning normally again.

Do I need an Apple Watch app to communicate between iPhone and Apple Watch?

This question is already answered over at Apple developer forums

Basically, watch this video. If you skip to ~32:00 minutes, the keynote speaker called Mark is implementing Healthkit in it's Watch App. The BPM is monitored after authorizing on your iPhone the app may use HealthKit and will refresh the heartbeat every ~4 seconds.

High level overview:

  • Yes, you will need a watch version of the iPhone app to get realtime data.
  • Create a companion app, and request read access to healthkit heart rate measurement.
  • Then start a workout session from your app

You may also find this SO link helpful for some sample code: Watch os 2.0 beta: access heart beat rate



Related Topics



Leave a reply



Submit