【问题标题】:iOS : Healthkit get Oxygen Saturation in real timeiOS:Healthkit 实时获取氧饱和度
【发布时间】:2018-04-26 07:34:29
【问题描述】:

我是 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:我正在模拟器中检查

我从那个 repo 获得心率,但氧气水平是空的?

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

【问题讨论】:

  • 您确定要获得氧气水平的许可吗?
  • 是的,我已经添加了权限,任何具体的??
  • 我在授权时添加了读取权限
  • 是的,您已将其添加到正确的位置。但请确保它要求 VO2 max
  • @MoazKhan : 你也可以添加代码吗,它会帮助我更多:)

标签: ios swift healthkit health-monitoring


【解决方案1】:

watchOS 不会自动记录氧饱和度样本,因此您不应该期望得到任何结果,除非您的设备正在记录这种类型的样本并使用应用程序将它们写入 HealthKit。

【讨论】:

  • 那么我该怎么做才能得到结果??
  • 安装一个记录氧饱和度的应用程序。
  • 是否有任何 iOS 库可用于通过摄像头测量氧气水平?
  • 目前查询每 5 秒更新一次。我们可以将时间间隔更改为 10 秒或 1 分钟吗?
  • 用心率计算血氧有什么线索吗? @AbhishekThapliyal
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-05-17
  • 2016-09-25
  • 2018-08-31
  • 2018-01-15
  • 2018-04-01
相关资源
最近更新 更多