繁体   English   中英

如何将蓝牙数据写入苹果健康套件 iOS swift

[英]How to write bluetooth data into apple health kit in iOS swift

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

您收集 BLE 数据,提取值,然后在 HealthKitStore 中使用简单的保存 function。 (请务必先在授权期间提供写入权限。)。

这是用于血糖的样品 function。

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM