Question

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)?

Was it helpful?

Solution

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.

OTHER TIPS

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with apple.stackexchange
scroll top