本文介绍了iOS HealthKit如何保存心率(bpm)值?迅速的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
使用方法:HKUnit
How to use : HKUnit
样本类型单位类型单位名称单位字符串
心率计数/时间每分钟节拍数计数/分钟
Sample type Unit type Unit name Unit stringHeart Rate count/time Beats per Minute "count/min"
推荐答案
Swift:心率(bpm)保存到healthkit商店
Swift : Heart Rate (bpm) save into healthkit store
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)值?迅速的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!