I have an application that collects healthkit data from iOS. It sends the data to my application like this:
{
"header": {
"id": "18018B64-850A-4F3A-9D21-4FF0C99762D6",
"creation_date_time": "2020-01-15T14:15:00.000+01:00",
"schema_id": {
"namespace": "omh",
"name": "step-count",
"version": "1.0"
}
},
"source": {
"operating_system_version": "13.3.0",
"bundle_identifier": "com.garmin.connect.mobile",
"product_type": "iPhone10,4",
"name": "Connect",
"version": "20"
},
"device": null,
"body": {
"step_count": 888,
"effective_time_frame": {
"time_interval": {
"start_date_time": "2020-01-15T14:15:00.000+01:00",
"end_date_time": "2020-01-15T14:29:59.000+01:00"
}
}
}
},
I want the separate data, because my app shows its own aggregations (day, month, today, etc) and I want to do this as I wish on server side, so I don't have access to the users phone. The users phone sends new measurements to the server as they are available in the background.
But, the issue is that I also receive measurements that are from iPhone iteself, or another device collecting stepcounts.
I could filter the incoming data for one device, but that means that if we turn off the watch, we miss data. Healthkit does collect iPhone data, so in the Health app you do see stepcounts.
I actually want to see the data that is in the healthkit app, so I get updated constantly.
Short question: I don't want to have to think about the device, I just want the HK value as it changes. Is this possible?
The way to reproduce the aggregates shown in Health on iOS is to use HKStatisticsCollectionQuery
rather than uploading individual samples and then attempting to compute the values for charts yourself. It's unlikely that you will be able to reproduce the logic that HKStatisticsCollectionQuery
uses to combine overlapping data, so it is much more straightforward to use the query directly.