I am trying to use heartRateVariabilitySDNN. I successfully get heartRate by query and I use the following code for getting heartRateVariabilitySDNN
but have no idea how it works. Also there is no proper documentation about this query or sample code from Apple.
func createheartRateVariabilitySDNNStreamingQuery(_ workoutStartDate: Date) -> HKQuery? {
let typeHeart = HKQuantityType.quantityType(forIdentifier: .heartRateVariabilitySDNN)
let predicate: NSPredicate? = HKQuery.predicateForSamples(withStart: workoutStartDate, end: nil, options: HKQueryOptions.strictEndDate)
let squery = HKStatisticsQuery(quantityType: typeHeart!, quantitySamplePredicate: predicate, options: .discreteAverage, completionHandler: {(query: HKStatisticsQuery,result: HKStatistics?, error: Error?) -> Void in
DispatchQueue.main.async(execute: {() -> Void in
print("got: \(String(describing: result))")
})
})
return squery
}