iOS使用日期和自定义时间将心率bpm值保存到Healthkit
我正在使用此代码将心率值保存到HealthkitiOS使用日期和自定义时间将心率bpm值保存到Healthkit,ios,healthkit,Ios,Healthkit,我正在使用此代码将心率值保存到Healthkit let heartRateCountUnit = HKUnit.count() let beatsPerMinuteQuantity = HKQuantity(unit: heartRateCountUnit.unitDivided(by: HKUnit.minute()), doubleValue: Double(heartRate)) let beatsPerMinuteType
let heartRateCountUnit = HKUnit.count()
let beatsPerMinuteQuantity = HKQuantity(unit: heartRateCountUnit.unitDivided(by: HKUnit.minute()), doubleValue: Double(heartRate))
let beatsPerMinuteType = HKQuantityType.quantityType(forIdentifier: .heartRate)!
let heartRateSampleData = HKQuantitySample(type: beatsPerMinuteType, quantity: beatsPerMinuteQuantity, start: Date(), end: Date())
healthKitDataStore?.save([heartRateSampleData]) { (success: Bool, error: Error?) in
completion (success)
if success {
print("Heart rate \(heartRate) saved.")
}
else {
print("Error")
}
}
如何在保存时添加自定义时间,例如时间选择器的时间