Hello Apple Community,
What does approach use the Fitness app for swimming distance calculation per set (segment)?
I've tried 2 options but all of them have different values than in the Fitness app.
Calculation like that: pool length * number of laps = swimming distance BUT the Fitness app sometimes shows other values for distance per set (segment).
Fetch all distance values via HKQuantityTypeIdentifier.distanceSwimming (HKSampleQuery`) and than try to match distance values with set (segment) duration. Again I got other values for swimming distance per set, values are bigger than in the Fitness app.
let healthStore = HKHealthStore()
let distanceType = HKQuantityType.quantityType(forIdentifier: HKQuantityTypeIdentifier.distanceSwimming)!
let predicate = HKQuery.predicateForSamples(withStart: startDate as Date, end: endDate as Date?, options: .strictStartDate)
let query = HKSampleQuery(sampleType: distanceType, predicate: predicate, limit: HKObjectQueryNoLimit, sortDescriptors: [.init(keyPath: \HKSample.startDate, ascending: true)], resultsHandler: { (query, results, error) in
if let error {
Logger.e("\(error)")
continuation.resume(returning: nil)
}
continuation.resume(returning: results)
})
healthStore.execute(query)
Is it possible to get the same swimming distance like in the Fitness app per set via HealthKit?
Topic:
App & System Services
SubTopic:
Health & Fitness