Duplicate entries of data in the Health app

We integrate Healthkit in our Fitness app and asked permission to write data for Active energy, Steps and Walking plus running distance.


Whatever data collected from our Fitness device, we process it and write individually in the Apple Health, it is working as expected.


Recently, we are trying to contribute our Fitness data into Apple watch activity ring, For that, we asked Workout permission, we followed the article which is posted on the developer apple documentation website. We implemented the same and It is working, We can see our Fitness data in the activity ring.


Now, we have a total of Four permissions from the Healthkit to write data.


So, whenever, our Fitness device sends data to our App, Our app process it and writes data for Active energy, Steps, Walking plus running distance and Workout(samples for Apple watch Activity ring) in the Health app. While creating a workout sample we are adding additional information in the Workout like Active energy, Steps and walking plus running distance.


In the Apple Health app, when we check what data our application has written, we found double entries.


As per our observation, if we revoke workout permission from Health app and write data only for the remaining three permissions then it’s working aspected and showing correct entries in the Health app. But it’s creating duplicate entries if we write data for all permission that we have asked.


It is working fine(show correct entries in the Apple Health app) if we write only three Active energy, Steps, Walking plus running distance or if write only a Workout but it showing duplicate entries if we write data for all.


Now, my question is,

Is there any way to prevent duplicate entries in the Healthkit app? What is a better approach to writing data in the Health app along with all permissions Active energy, Steps, Walking plus running distance and Workout?


Any help is appreciated.

Duplicate entries of data in the Health app
 
 
Q