我有使用蓝牙血压,血糖从第三方设备获取的数据,我想将这些数据发送给苹果健康公司,即将数据写入苹果健康公司,任何人都可以使用swift 5提供示例。
wangsdfsdfsfdgdf 回答:如何在iOS Swift中将蓝牙数据写入Apple Health Kit
您收集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