react-native-healthkit icon indicating copy to clipboard operation
react-native-healthkit copied to clipboard

Incorrect metadata key name for deduplicating records

Open mordechaim opened this issue 3 years ago • 3 comments

https://github.com/Kingstinct/react-native-healthkit/blob/49c81d7fcf75e7e970c6841696c858a5d0e73ce5/src/native-types.ts#L328-L329

According to Apple, the correct names are HKMetadataKeySyncIdentifier and HKMetadataKeySyncVersion. I actually tried both key names, but only the HKMetadataKeyXXX key correctly deduplicated the data.

Thanks for this amazing library; it's the most comprehensive react native bridge for HealthKit ❤️

EDIT: I now notice other keys missing the MetadataKey prefix, such as HKMetadataKeyReferenceRangeLowerLimit

mordechaim avatar Nov 07 '22 18:11 mordechaim

Thanks @mordechaim! :)

I'd be superhappy for a PR on this. Since it's JSON being sent over the native bridge - just updating the TypeScript types to reflect the Apple recommended metadata keys should result in expected behaviour here.

robertherber avatar Nov 07 '22 22:11 robertherber

I'm not quite sure about which naming convention is being used by Apple here actually. On my sleep samples I'm getting HKTimeZone and not HKMetadataKeyTimeZone, and that's coming straight from Apple Watch.

The data you're looking at - is it coming from Apple or from another data source @mordechaim? I think the docs and actual keys used by Apple might have confused not only us - but other developers using HealthKit as well.

robertherber avatar Dec 08 '22 09:12 robertherber

This is indeed confusing.

I'm pushing to HealthKit and in order to deduplicate data (sending over an updated step count for the hour will add instead of update) I need to pass the 2 keys mentioned above. I tried using the keys without HKMetadata* prefix and it did not properly deduplicate.

(Sorry for not following up with a PR, I'm not a TypeScript guy and fear I'll do it incorrectly)

mordechaim avatar Dec 08 '22 19:12 mordechaim