我找不到显式方法来更新 HKHealthStore 中的样本,所以我正在做的是删除一个样本并添加更新样本。
public func deleteGlucoseMeasurement(measurement: Measurement, completion: @escaping (Bool, Error?) -> Void) {
Health.shared.delete(measurement.sample, withCompletion: completion)
}
public func updateGlucoseMeasurement(unit: Health.Unit, measurement: Measurement, completion: @escaping (Bool, Error?) -> Void) {
deleteGlucoseMeasurement(measurement: measurement) { (success, error) in
if(error != nil || !success) {
completion(success, error)
return
}
self.saveGlucose(unit: unit, glucose: measurement.glucose, description: measurement.description, date: measurement.date, completion: completion)
}
}
但是我收到了 错误:可选(“无法找到某些要删除的对象。”),用于我的应用未添加的示例。
那么有没有办法更新这样的样本,或者至少检查一下这样的样本是否可编辑?