iOS近乎实时地从Apple Watch获得心率 [英] iOS get heart rate from Apple Watch in near real time

查看:1157
本文介绍了iOS近乎实时地从Apple Watch获得心率的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要制作一个能够近乎实时记录心率数据的应用程序,并尽快将此数据发送到服务器。

I need to make an app that records heart rate data in near real time and send this data to a server as soon as possible.

首先我采用了这种方法:观看os 2.0测试版:访问心率

First I took this approach: Watch os 2.0 beta: access heart beat rate

事实上它工作正常。 HealthKit每五秒钟会有一个新的心率数据。但现在我遇到的问题是我无法与服务器同步。

In fact it is working fine. There is new heart rate data in the HealthKit every five seconds. But now I have the problem that I can't sync that with a server.

我的第一个方法是Watch应用程序。手表正在向服务器发送数据。这不起作用,因为一旦手表上的屏幕变黑,它就会停止发送。

My first approach was the Watch app. The watch was sending data to a server. That doesn't work because as soon as the screen turns black on the watch, it stops sending.

我的下一个方法是每五秒钟在iPhone上查询一次HealthKit以获取新数据。这是有效的,只要应用程序在前台。

My next approach was to query the HealthKit on the iPhone every five seconds for new data. This works, as long as the app is in foreground.

然后我看到有某种背景功能可以监视HealthKit本身并从后台撤消应用程序可以做些什么。(enableBackgroundDeliveryForType)这似乎不适用于心率(Apple文档说这些步骤不起作用,我猜心率就是其中之一)。

Then I saw that there's some kind of background functionality that watches the HealthKit itself and revokes the app from background and you can do something.(enableBackgroundDeliveryForType) This doesn't seem to work for heart rate (the Apple Documentation says for things like steps this doesn't work, I guess heart rate is one of those).

我现在被困住了。你知道怎么做吗?我需要在iPhone上每5-10秒执行一次后台任务。这似乎是不可能的

I'm stuck now. Do you know how to it? I would need some background task that is executed every 5-10 seconds on the iPhone. That seems to be impossible

推荐答案

更新

正如@BootMaker所注意到的,Apple在 WatchOS 3 中为 HKWorkout 应用程序提供了后台模式,因此它现在正在运行。您必须运行 HKWorkoutSession ,即使应用程序处于后台(观看黑屏),这也会实时保持您的实时交付

As noticed by @BootMaker, Apple made background mode available for HKWorkout apps in WatchOS 3, so it's working now. You have to run a HKWorkoutSession and this will keep your heartrate delivery in real time even when the app is in the background (dark screen on watch)

当手表应用程序打开时,最近

The closest you are going to be is while the watch app is open.

为什么我要陈述这个?


  1. 有两个HealthKit的数据库(一个在iPhone上,另一个在Apple Watch )。当他们同步是任意的并且仅由操作系统决定时

  1. There are two HealthKit's Database (one at the iPhone and another at the Apple Watch). When they sync is arbitrary and decided only by the O.S.

您最接近 实时 当您有任何密码锁定 iPhone Apple Watch 中的屏幕时。
无论哪种方式,都不能保证每次将新措施添加到 Apple Watch的HealthKit

The closest you are going to be to real time is when you don't have any password locking your screen in iPhone or Apple Watch. Either way, there's no guarantee that the sync will happen every time a new measure is added to Apple Watch's HealthKit

强迫心率传感器实时工作的唯一方法是通过锻炼观察者,同时 Apple Watch应用位于 FOREGROUND

The only way to force the Heart rate sensor into working in real time is via workouts or observer while your Apple Watch app is in FOREGROUND.

Apple Watch应用程序的后台投放

Background delivery is NOT available for Apple Watch apps.

观看操作系统2 请求传感器每10分钟自动测量一次(在后台)。

Watch OS 2 request the sensor to measure automatically (in background) every 10 minutes minimum.




没有其他解决方法,如果您需要实时如果用户不使用您的应用,您需要使用专业的可穿戴设备

There's no other workaround, if you need real time for longer periods, or while the user is not using your app, you will need to use an specialized wearable.

这篇关于iOS近乎实时地从Apple Watch获得心率的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆