07-31-2018 07:10
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post

07-31-2018 07:10
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post
Hey, I am developing an app which shows data from both Apple Health and Fitbit web api. I am seeing duplicate data. Is there any way to know that data is duplicate and hide it.

07-31-2018 08:33
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post


07-31-2018 08:33
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post
I have moved your post to the API Forum @pawan-sharma.
My thought is that since your getting data from two different sights, duplicates would need to be determined by your logic.
Someone here might know of another trick.

07-31-2018 21:39
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post

07-31-2018 21:39
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post
Use metadata to identify your records and let Apple Health de-duplicate. Here is the method I use to create my samples. Note the metadata dictionary. HKMetadataKeySyncIdentifier is a string that is constant for each datapoint. I change HKMetadataKeySyncVersion when my data changes. I assume my data is always changing, and use the number of seconds since epoch to provide an ever-increasing version number.
private func createHealthKitSample(date: String, time: String, quantity: Double, unit: HKUnit, type: HKQuantityType) -> HKQuantitySample { let dateFormatter = DateFormatter() dateFormatter.dateFormat = "yyyy-MM-dd HH:mm:ss" // TODO Correct times to UTC by combining timezone offset from profile let start = dateFormatter.date(from: "\(date) \(time)")! let end = start.addingTimeInterval(60) let metadata = [ HKMetadataKeySyncIdentifier: "fitbit-connector-\(type.identifier)-\(start)", HKMetadataKeySyncVersion: Date().timeIntervalSince1970 ] as [String : Any] return HKQuantitySample( type: type, quantity: HKQuantity(unit: unit, doubleValue: quantity), start: start, end: end, metadata: metadata ) }

