07-31-2018 07:10
07-31-2018 07:10
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.
Best Answer07-31-2018 08:33
Platinum Fitbit Product Experts share support knowledge on the forums and advocate for the betterment of Fitbit products and services. Learn more
07-31-2018 08:33
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.
Best Answer07-31-2018 21:39
07-31-2018 21:39
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
)
}
Best Answer