steps count mismatch Apple health kit app to our custom App

Dear Apple Support  Team,

 

We are an enterprise user and creating an app to drive fitness challenge in our organization. We would be displaying challenges to participate and  given them option to see the progress on daily basis.  

To achieve that we are getting step Count/distance covered data from HealthKit.

 

However, while doing so we are facing the below issue

 

When we compared the HealthKit data which we receive and the data we see in Health App in iPhone are different. Example: healthkit data which we get shows 15000 steps but when we compare the steps with the user it is around 12000 steps. We are getting it in excess always. How do we solve this ?

 

Does Health App Combine the steps tracked through iPhone and apple watch ? If we walk with the iPhone and Fitness watch, both device will record data in same time ? Will it add both or merge to avoid duplicates ?

 

We tried to create running challenge but we are getting distance for the users though the user did not run. The user actually walked without initiating the Running but still we get the data under running with the distance. Can we get unique records for running and walking ?

 

HealthKit does not distinguish between walking and running distances; there is only a single data type for both. You would need to create your own heuristics for determining one versus the other if you needed that.

As for the discrepancy you are seeing, how are you querying for steps data? If the user has both iPhone and Apple Watch, data will be collected on both and you will need to handle merging those data streams to produce a useful estimate. If you query for data using HKStatisticsCollectionQuery, HealthKit will do the appropriate merging for you: this is what Health is doing when you're looking at data in that app. If you're simply using HKSampleQuery (or one of the other non-statistics queries) you will have to select between overlapping samples within your app, and it is unlikely that you will be able to match HealthKit's merge algorithm correctly.

The same is true for all quantity types: If you want to match Health and take advantage of HealthKit's built-in source merging, you'll need to use HKStatisticsQuery or HKStatisticsCollectionQuery.

steps count mismatch Apple health kit app to our custom App
 
 
Q