Writing Data to Apple Health Without Duplicates
Apple Health uses the submission and reading of data received by HealthKit, and in many cases we see them as the same thing from the point of view of programming, short for HK.
HK has a special place in terms of competence management (yi) and a pit, i.e. reading and writing rights are completely separate and there are written but not readable situations. Since the right of control is in the exclusive hands of the user, even if the application is accompanied by a request for read-and-write permission, it may simply be granted without the right to read. This creates a problem: the program cannot know directly what data is stored in the HK, and if no attempt is made to circumvent the pit, the same data may be duplicated in the HK.
In order to avoid double-entrying, we need to mark every data that needs to be synchronized to HK in the data storage at the AP end and even at the cloud end. In this way, HK data can be synchronized to the best.
Personally, I have an idea about HK's own design: HK should automatically merge the same data submitted from the same data source. If a few data, their starting time, values, etc., are the same, it is perfectly reasonable to see them as the same data. In fact, HK has an integrated algorithm for duplicate data and does not add up data. However, when the user point “Show All Data”, it sees a repetition of data, and more or less has a certain level of resonance and blames the APP side. Apples are particularly important for the data privacy of HK to design such a strange licensing mechanism at the expense of its availability.