Observing heart rate from Apple watchOS2 workout in realtime on IOS9 app?

I created a HKObserverQuery for HKQuantityTypeIdentifierHeartRate which works fime when the app starts or if the app goes to background and back to foreground, only at that stages I see the health kit data from a running watch workout IN REALTIME. That means the data is transmitted to the iPhone in realtime but the HKObserverQuery only fires at startup or when coming back to foreground. Is this a bug?


PS: If I enter mannualy a heart rate into the health app on the iPhone the HKObserverQuery fires correct!

Here is my code snipp:

if ([HKHealthStore isHealthDataAvailable]) {

NSSet *readDataTypes = [self dataTypesToRead];


[self.healthStore requestAuthorizationToShareTypes:nil readTypes:readDataTypes completion:^(BOOL success, NSError *error) {

if (!success) {

NSLog(@"%@ - You didn't allow HealthKit to access these read/write data types. In your app, try to handle this error gracefully when a user decides not to provide access. The error was: %@. If you're using a simulator, try it on a device.", [self class], error);

return;

} else {

UIBackgroundTaskIdentifier __block taskID = [application beginBackgroundTaskWithExpirationHandler:^{

if (taskID != UIBackgroundTaskInvalid) {

[application endBackgroundTask:taskID];

taskID = UIBackgroundTaskInvalid;

}

}];

HKSampleType *sampleType = [HKObjectType quantityTypeForIdentifier:HKQuantityTypeIdentifierHeartRate];

[healthStore enableBackgroundDeliveryForType:sampleType frequency:HKUpdateFrequencyImmediate withCompletion:^(BOOL success, NSError *error) {}];

HKQuery *query = [[HKObserverQuery alloc] initWithSampleType:sampleType predicate:nil updateHandler:

^void(HKObserverQuery *query, HKObserverQueryCompletionHandler completionHandler, NSError *error)

{

if (error) {

NSLog(@"*** An error occured while setting up the observer. %@ ***",

error.localizedDescription);

abort();

} else {

NSLog(@"*** Setting up the observer. SUCCESS ***");

}

/

if (completionHandler) {

completionHandler();

}

NSLog(@"*** NEW or DELETED heart rate data ***");

/

if (taskID != UIBackgroundTaskInvalid) {

[application endBackgroundTask:taskID];

taskID = UIBackgroundTaskInvalid;

}

}];

[healthStore executeQuery:query];

}

}];

}

Ron Wood, where you able to solve this somehow? I'm experiencing the exact same issue! (the updateHandler seems to be called the very first time and whenever the app comes back to the foreground from background) it doesn't actually live update when being in the foreground (even if I have a workout session active in the Apple Watch and/or I explicitly query my heart rate data in the heart date app of the apple watch).
You cannot observe watch data on phone in this manner. Data syncs from watch to phone on a periodic cadence and on certain triggers (e.g. when a HealthKit enabled app is foregrounded). It does not stream.
Ok, thank you very much for the reply! So if my intention is to integrate live data from the Apple Watch into my app there's no other way than actually creating an Apple Watch app (or extension) that would communicate with my iOS app?
Observing heart rate from Apple watchOS2 workout in realtime on IOS9 app?
 
 
Q