【问题标题】:How to write bluetooth data into apple health kit in iOS swift如何在 iOS swift 中将蓝牙数据写入苹果健康套件
【发布时间】:2020-03-01 15:20:39
【问题描述】:

我有来自使用蓝牙血压、血糖的第三方设备的数据,我想将这些数据发送到苹果健康,即将数据写入苹果健康,任何人都可以提供使用 swift 5 的示例。

【问题讨论】:

    标签: ios swift bluetooth


    【解决方案1】:

    您收集 BLE 数据,提取值,然后在 HealthKitStore 中使用简单的保存功能。 (一定要在授权时先提供写权限!)。

    这是一个血糖的示例函数。

    func writeBloodGlucose(value: Double, measurementDate: Date) throws {
        let healthStore = HKHealthStore()
        let bloodSugar = HKQuantitySample(
            type: HKObjectType.quantityType(forIdentifier: .bloodGlucose)!,
            quantity: HKQuantity(
                unit: HKUnit.gramUnit(with: .milli).unitDivided(by: HKUnit.liter()),
                doubleValue: value
            ),
            start: measurementDate,
            end: measurementDate,
            device: HKDevice(
                name: "name",
                manufacturer: "manufacturer",
                model: "model",
                hardwareVersion: "hardwareVersion",
                firmwareVersion: "firmwareVersion",
                softwareVersion: "softwareVersion",
                localIdentifier: "localIdentifier",
                udiDeviceIdentifier: "udiDeviceIdentifier"
            ),
            metadata: nil)
        healthStore.save(bloodSugar) { (success, error) in
            print(success)
            print(error)
        }
    }
    

    如果您愿意,我已经开发了一个 CocoaPod,它可以简化 AppleHealth 的写入/读取数据。这是链接:https://cocoapods.org/pods/HealthKitReporter

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-02-11
      • 1970-01-01
      • 2016-07-09
      • 1970-01-01
      相关资源
      最近更新 更多