HKSampleQuery In Complication Update

Does anyone know of a reason why I seem unable to use an HKSampleQuery if it is called inside getNextRequestedUpdate(). The code inside the aSyncronous query is never called. I am trying to use an HKSampleQuery to update a complication when the getNextRequestedUpdateDate time is reached. The HKSampleQuery Code works fine in the open Watch app but not in the complication controller. I am aware that HKSampleQuerys do not work when the device is locked due to privacy reading but this should not be the case.

I am using device testing and not the simulator.

Replies

Could you store it as a NSUserDefault and request it from the complication? I believe we have a very short period of time to update our complications.

Its not a case of where I store it. I need live data updates when the complication update calls. The time to update (relatively) is irrelevent because I'm not even gettin code executed, let alone how long it takes to execute.

You can execute the query, but you cannot read the result.

I tested many times.

I guess that's because HKSampleQuery uses a callback to read the result, not synchronizely, so you cannot read the result in complication udpate.

Is there a reason for this or is there a work around? because im sure ive seen complication on the app store that use healthkit data such as steps

You can use the accelerometer, but not the healthkit in this case, I think

Is that mentioned in documentation anywhere? Cheers

There is a limitation that HealthKit data store is locked if the phone is locked. The query will still run, but you will get no results in that case. The watch will follow phone, although it will allow you to read the data if you have allowed the watch to unlock with wrist raise, and it is already unlocked because it is tied to your unlocking of the phone (and it's on your wrist.) Maybe this is what kinfkong ran in to?


All that may be hard to follow. Just remember HealthKit is considered secure data. If testing, you may want to turn off passcode locks initially to see if data is being read properly.

CobraPA, that's an amazing idea. I assumed that the watch was just 'unlocked' when attached to the users wrist and passcode then entered. So what I get from your post is that if the 'wrist is raised' the sample should work, but otherwise if the watch is just display off etc.. And the complication update calls in the background it doesn't work? I'm gunna try setting a complication and keeping the watch face awake for 30 mins, (should be fun). And see if it updates properly. Thanks again

It's possible to received live heath kit data on iPhone.

The health kit data from Apple Watch is stored in Heart Store on iPhone. The watch synchronizes data with iPhone in background. If you will execute an observer query on iPhone you will receive data once in 30 minutes on iPhone.


1. Start workout session on Apple Watch app.

2. Execute observer query for the recorded heart rate on iPhone.

3. Then the watch app can be locked or what ever.

4. The health kit data from Apple Watch is pushed into Heart Store on iPhone at some moments

5. Your observer query on iPhone will received data once in 30 minutes.


Probably you can request to update your complication from iPhone and hopefully it can take prepared data from a shared storage, e.g. from NSUserDefault (I didi not tried it yet).


Take a look on example console log of my iPhone app (note the timestamps):

https://drive.google.com/file/d/0B741Iff4HSM8OE1ZdUxkdWdIUVk/view?usp=sharing

Any other ideas on this CobraPA? cause I still have had no luck... Cheers