如何使用:HKUnit
样本类型 单位类型 单位名称 单位字符串 心率 count/time Beats per Minute "count/min"
最佳答案
Swift:心率 (bpm) 保存到 healthkit 商店
private func saveHeartRateIntoHealthStore(height:Double) -> Void
{
// Save the user's heart rate into HealthKit.
let heartRateUnit: HKUnit = HKUnit.countUnit().unitDividedByUnit(HKUnit.minuteUnit())
let heartRateQuantity: HKQuantity = HKQuantity(unit: heartRateUnit, doubleValue: height)
var heartRate : HKQuantityType = HKQuantityType.quantityTypeForIdentifier(HKQuantityTypeIdentifierHeartRate)
let nowDate: NSDate = NSDate()
let heartRateSample: HKQuantitySample = HKQuantitySample(type: heartRate
, quantity: heartRateQuantity, startDate: nowDate, endDate: nowDate)
let completion: ((Bool, NSError!) -> Void) = {
(success, error) -> Void in
if !success {
println("An error occured saving the Heart Rate sample \(heartRateSample). In your app, try to handle this gracefully. The error was: \(error).")
abort()
}
}
self.healthStore!.saveObject(heartRateSample, withCompletion: completion)
}// end saveHeartRateIntoHealthStore
关于iOS HealthKit 如何保存心率 (bpm) 值? swift ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27268665/