gpt4 book ai didi

iOS : Healthkit get Oxygen Saturation in real time

转载 作者:行者123 更新时间:2023-11-30 11:33:05 26 4
gpt4 key购买 nike

我是 HealthKit 框架的新手,想要实时了解血流中的氧饱和度。

引用: https://github.com/coolioxlr/watchOS-2-heartrate

从这个存储库中,我尝试查询氧饱和度

   func createOxygenSaturationStreamingQuery(_ workoutStartDate: Date) -> HKQuery? {

guard let quantityType = HKObjectType.quantityType(forIdentifier: .oxygenSaturation) else { return nil }
let datePredicate = HKQuery.predicateForSamples(withStart: workoutStartDate, end: nil, options: .strictEndDate )

let predicate = NSCompoundPredicate(andPredicateWithSubpredicates:[datePredicate])

let oxygenSaturationQuery = HKAnchoredObjectQuery(type: quantityType,
predicate: predicate,
anchor: nil,
limit: Int(HKObjectQueryNoLimit)) { (query, sampleObjects, deletedObjects, newAnchor, error) -> Void in

self.updateOxygenSaturation(sampleObjects)
}

oxygenSaturationQuery.updateHandler = {(query, samples, deleteObjects, newAnchor, error) -> Void in
self.updateOxygenSaturation(samples)
}
return oxygenSaturationQuery
}

func updateOxygenSaturation(_ samples: [HKSample]?) {

guard let oxygenSaturationSamples = samples as? [HKQuantitySample] else {return}

DispatchQueue.main.async {
// RETURN FROM HERE AS EMPTY ARRAY
guard let sample = oxygenSaturationSamples.first else { return }
let value = sample.quantity.doubleValue(for: HKUnit(from: "%/min"))
let stringValue = String(UInt16(value))
self.label.setText(stringValue)
// retrieve source from sample
let name = sample.sourceRevision.source.name
print("sample.sourceRevision.source.name : \(name)")
print("PERCENT : \(stringValue)")
}
}

P.S:我正在检查模拟器

我正在从该存储库获取心率,但氧气水平为空?

让我知道我做错了什么以及如何改正?

最佳答案

watchOS 不会自动记录氧饱和度样本,因此除非您拥有记录此类样本并使用应用程序将其写入 HealthKit 的设备,否则您不应期望获得任何结果。

关于iOS : Healthkit get Oxygen Saturation in real time,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50037317/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com