recalibrateEstimates(sampleType:date:completion:)
Recalibrates the prediction algorithm used to calculate the specified sample type.
Declaration
func recalibrateEstimates(sampleType: HKSampleType, date: Date, completion: @escaping @Sendable (Bool, (any Error)?) -> Void)func recalibrateEstimates(sampleType: HKSampleType, date: Date) async throwsParameters
- sampleType:
The sample type to recalibrate.
- date:
The effective date for the recalibration.
- completion:
A completion block that the system calls after recalibrating the data used by the prediction algorithm. The system passes the following parameters:
successA Boolean value that indicates whether the system successfully recalibrated the sample type’s estimates.
errorIf
successis False, this parameter contains error information; otherwise, it’snil.
Discussion
Your app can use this method to recalibrate HealthKitʼs prediction algorithms after an event that may significantly affect their results. For example, you can recalibrate the sixMinuteWalkTestDistance type to use only data collected after a mobility-impacting health event, such as surgery or an injury. Recalibrating sixMinuteWalkTestDistance after such an event may yield more accurate estimates during the recovery period.
Check the HKSampleType class’s allowsRecalibrationForEstimates method to see if a given sample type supports recalibrating the algorithm.
The following sample code recalibrates the estimates for the six-minute walk test.
// Access the HealthKit Store.
let healthStore = HKHealthStore()
// Get the six-minute walk test type.
let sixMinuteWalkType = HKQuantityType(.sixMinuteWalkTestDistance)
// Verify that the type supports resetting estimates.
if sixMinuteWalkType.allowsRecalibrationForEstimates {
// Reset the estimate.
healthStore.recalibrateEstimates(sampleType: sixMinuteWalkType, date: Date()) { (success, error) in
// Check the success value.
if !success {
if let error = error {
// Handle errors here.
}
}
}
}