7

What happens when more than one "source" registered with HealthKit tracks the same activity?

For example, if I have Human tracking my activity in general, and then use Cyclemeter (which supports HealthKit in version 10.3) to track particular bike ride, both will (I assume) submit the same activity to HealthKit. Presumably it should be possible for HealthKit to recognize that these activities are likely duplicates and at least ask me how to resolve the "duplication" (much as sync conflicts are resolved). In fact, the activities contain enough data that such recognition should generally be possible to perform automatically.

Does HealthKit do this? Does it resolve duplicate recordings of the same activity (either automatically or semi-automatically)?

  • This might be premature since Cyclemeter 10.3 is not released to the app store yet. Apple is clearly changing the health kit code with 8.0.2 release of iOS. – bmike Sep 29 '14 at 14:51
  • @bmike: Cyclemeter is just an example: the question applies to any two or more sources. – orome Sep 29 '14 at 14:52
  • AFAIK there are zero apps in the app store that inject data into health kit hence my suggesting this is premature. I'm sure developers have known since June how Apple has coded things to work, but until the code hits the streets we won't know what Apple has actually coded and released. My guess is that data will be tagged by reverse domain name and you will get two sets of distinct data with no merging - but that's just guesswork at this point. – bmike Sep 29 '14 at 14:55
  • @bmike: Several apps now (8.0.2) work with HealthKit as sources. Check the app store. – orome Sep 29 '14 at 14:57
  • Why not edit in specific apps that actually work then into your question? – bmike Sep 29 '14 at 15:18
9

HealthKit is pretty smart with your data. For every source in the Health app, you can set the priority of difference apps. Tap one of the metrics in the Health app tap Share data > Edit to drag sources in the right order.

If other apps request data, HealthKit will automatically merge the datasets, probably based on timestamps. It picks the high priority app first, and fills the gaps in data with the number 2 app, etc.

This WWDC would be a great start to get a complete overview.

2

As far as I researched the answer of Paul Veugen is only partially true. HealthKit does merge this Data if you use a HKStatisticsQuery or a HKStatisticsCollectionQuery. Otherwise it will be up to you, to provide a logic to merge/deduplicate the results.

One possible solution might be to use HKSourceQuery to Identify different sources and e.g. only select one.

Another might be to access the source via HKSourceRevision in the results of an HKQuery and only take the data from one source or try to compare data from the different sources. From iOS 9.3 there is also the possibility to access the different source devices using HKDevice.

Taking one device will always leave you with the possiblity, that an user did partially not use the device during the requested timespan, what will lead to missing datapoints.

Because of this priorising results will still remain painful, as Apple did not document, if the requested data will be sorted by the user defined source priority in Health.

Saying this, it might be worth looking into overlapping date ranges to identify duplicates.

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.