iOS HealthKit 如何保存心率 (bpm) 值? swift

标签 ios swift rate healthkit

如何使用: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/

相关文章:

ios - Xcode 9 代码片段错误

iphone - 有没有办法找到 UINavigationBar 标题的字体和框架大小?

ios - 有没有办法在应用程序已经运行时使用 Branch 深层链接?

Swift:动态库和 AFNetworking

ios - Swift 中带有选择器的协议(protocol)扩展

java - java中的速率控制

ios - 自动调整 iPhone 4S 和 iPhone 5 的 UI 元素

mysql - 需要Mysql评级和排名教程

c# - 在 C# 中获取视频时长、帧速率和其他属性

ios - 自定义 View TextField 如何计算TextField总和