简体   繁体   English

在iOS HealthKit App中获得心率的最佳方法?

[英]Best Way to get Heart Rate in iOS HealthKit App?

I'm writing an iOS app to display real-time Heart Rate from a BTLE device (the Polar H7). 我正在编写一个iOS应用,以显示来自BTLE设备(Polar H7)的实时心率。 I've found 2 ways to do this: 我发现了两种方法可以做到这一点:

  1. Using CBCentralManager and bit-twiddling the Heart Rate Measurement Characteristic by hand 使用CBCentralManagerCBCentralManager 心率测量特征
  2. Using HealthKit's HKObserverQuery 使用HealthKit的HKObserverQuery

As I see it, there are pros/cons to each approach. 如我所见,每种方法都有优点/缺点。

Using CBCentralManager enables more control (eg, you can store the sensor location) and quicker setup (ie, you can start displaying values immediately). 使用CBCentralManager可以实现更多控制(例如,您可以存储传感器位置)和更快的设置(即,您可以立即开始显示值)。 But, from what I can tell, the BTLE device will not be seen by CBCentralManager if the BTLE device is already paired with HealthKit. 但是,从我所知道的,BTLE设备将不会被看到CBCentralManager如果BTLE设备已经与HealthKit配对。

Using HealthKit appears to be the preferred approach (and is much simpler to implement) but requires an extra trip to the Health app to turn on the "Update Health Data" switch. 使用HealthKit似乎是首选方法(并且更易于实现),但是需要额外运行Health应用程序才能打开“ Update Health Data”开关。

Should I implement both? 我应该同时实施吗? Has anyone dealt with this issue? 有人处理过这个问题吗?

I haven't dealt with your issue specifically, but I am working on HealthKit integration as well. 我没有专门处理您的问题,但是我也在进行HealthKit集成。 Based on what you've outline here, I would go with the HealthKit approach and only that approach unless there's some requirement to really push you do to both. 根据您在此处概述的内容,我将使用HealthKit方法,并且仅使用该方法,除非有一些要求使您同时采取两种方法。 If you do have to implement both, I would probably put some abstraction in there so the controllers don't have to know what the source is. 如果必须同时实现两者,那么我可能会在其中添加一些抽象,以便控制器不必知道源是什么。

I'm not sure about the extra trip to the Health app you mention. 我不确定您提到的“健康”应用程序的额外旅行。 You can ask for permission to the heart rate data from within your app using requestAuthorizationToShareTypes:readTypes:completion: . 您可以使用requestAuthorizationToShareTypes:readTypes:completion:从您的应用程序内请求获取心率数据。 Here's a tutorial that has a walk through, in case that helps at all: HealthKit Tutorial with Swift: Getting Started . 如果有帮助,这里有一个逐步讲解的教程:带Swift的HealthKit教程:入门

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM