【问题标题】:HealthKit Blood Oxygen SPO2HealthKit 血氧 SPO2
【发布时间】:2020-12-03 17:28:46
【问题描述】:

使用 Apple Watch 系列 6,您现在可以测量您的 SP02,即血氧中的血红蛋白含量。 iPhone 上的健康应用程序会显示呼吸部分中的所有测量值。这是 COVID 患者的关键组成部分。

无论如何我都无法以编程方式访问此信息。

我已经检查了最新 Apple 文档中的所有 HKObjectTypes。 iOS 开发者目前可以使用这些信息吗?

根据一些研究人员的要求,任何信息都会非常有用。

【问题讨论】:

标签: ios swift healthkit


【解决方案1】:

好的,有人告诉我这与氧饱和度相同。这是我用来查询 HK 的氧饱和度的代码:

    // Get SPO2
func getOxygenSaturation()
{
    // Type is SPO2 SDNN
    let osType:HKQuantityType = HKQuantityType.quantityType(forIdentifier: HKQuantityTypeIdentifier.oxygenSaturation)!

    let predicate = HKQuery.predicateForSamples(withStart: Date.distantPast, end: Date(), options: .strictEndDate)
    let sortDescriptor = NSSortDescriptor(key: HKSampleSortIdentifierStartDate, ascending: false)
    let osUnit:HKUnit = HKUnit(from: "%")

    
    let osQuery = HKSampleQuery(sampleType: osType,
                                 predicate: predicate,
                                 limit: 10,
                                 sortDescriptors: [sortDescriptor]) { (query, results, error) in
        guard error == nil else { print("error"); return }
        
        // Get the array of results from the sample query
        let sampleArray:[HKSample]? = results!
        
        // Loop through the array of rsults
        for (_, sample) in sampleArray!.enumerated()
        {
            // Be sure something is there
            if let currData:HKQuantitySample = sample as? HKQuantitySample
            {
                let os: Double = (currData.quantity.doubleValue(for: osUnit) * 100.0)
                let d1: Date = currData.startDate
                let str1 = SwiftLib.returnDateAndTimeWithTZ(date: d1, info: self.info!)

                Dispatch.DispatchQueue.main.async {
                    
                    self.tvOxygenValue.text = String(format: "%.0f%@", os, "%");
                    self.tvOxygenDate.text = str1
                    //print("\(os)");
                }
            }
        }
        
        print("Done")
        self.loadAndDisplayActivityInformation()
    }

    healthStore!.execute(osQuery)
}

【讨论】:

  • 以编程方式获得氧饱和度的解决方案是什么?
猜你喜欢
  • 1970-01-01
  • 2015-11-19
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-02-18
  • 2022-11-11
  • 1970-01-01
相关资源
最近更新 更多