首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >HealthKit血氧SPO2

HealthKit血氧SPO2
EN

Stack Overflow用户
提问于 2020-12-04 01:28:47
回答 1查看 456关注 0票数 0

有了苹果手表系列6,你现在可以测量你的SP02,你的血氧中的血红蛋白含量。iPhone上的健康应用程序会在呼吸部分向你显示所有的测量数据。这对于COVID患者来说是一个关键的组成部分。

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

我已经检查了最新的苹果文档中的所有HKObjectTypes。此信息目前对iOS开发人员可用吗?

正如几位研究人员所要求的那样,任何信息都将非常有用。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2020-12-05 00:45:10

好吧,我被告知这和Oxygen Saturation.Here是一样的,我用它来查询HK的血氧饱和度:

代码语言:javascript
复制
    // 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)
}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/65131045

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档