HKWorkoutSession:在watchOS 2中关闭屏幕时未获得心率 [英] HKWorkoutSession: Not getting Heart Rate when screen is turned off in watchOS 2

查看:439
本文介绍了HKWorkoutSession:在watchOS 2中关闭屏幕时未获得心率的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用iOS 9 beta 4和watchOS 2 beta 4.



当手表屏幕变黑时,我似乎无法获得任何心率数据(锁定)。我将接到 applicationWillResignActive 的电话,然后心率数据就会停止。



似乎传感器是屏幕锁定后,在一段时间后停用(不再是绿色)。



其他人是否看到此行为?如果有人在手表上的屏幕被锁定时获得心率数据,我可以发布我的代码来启动WorkoutSession。

解决方案

从watchOS 3.0开始,您可以将 WKBackgroundModes 条目与 workout-processing 值一起添加到扩展程序的Info.plist。 / p>

来自 docs


在后台运行锻炼会话可以在后台运行。
后台运行为应用程序授予以下能力:



该应用程序在整个训练期间继续运行,当用户降低手腕时甚至可以
或与其他应用互动。
当用户抬起手腕时,应用程序会重新出现,让用户快速轻松地检查他们当前的进度和性能。



应用程序可以继续从
背景中的Apple Watch传感器访问数据,让您始终保持应用程序的最新状态。对于
的例子,正在运行的应用程序可以继续跟踪用户的心率,
确保每当
用户抬起手腕时显示最新的心率数据。



I am using iOS 9 beta 4 and watchOS 2 beta 4.

I can't seem to get any heart rate data when the watch screen turns black (locks). I will get a call to applicationWillResignActive and then the heart rate data just stops.

It seems that the sensor is deactivating after some time as well (not green anymore), when the screen locks.

Anyone else seeing this behavior? I can post my code for initing the WorkoutSession if anyone else getting heart rate data when the screen on the watch is locked.

解决方案

Starting in watchOS 3.0 you can add the WKBackgroundModes entry with the workout-processingvalue to the extension's Info.plist.

From the docs:

Running in the Background Workout sessions can run in the background. Background running grants an app the following abilities:

The app continues to run throughout the entire workout session, even when the user lowers their wrist or interacts with a different app. When the user raises their wrist, the app reappears, letting the user quickly and easily check their current progress and performance.

The app can continue to access data from Apple Watch’s sensors in the background, letting you keep the app up to date at all times. For example, a running app can continue to track the user’s heart rate, ensuring that the most recent heart rate data is displayed whenever the user raises their wrist.

这篇关于HKWorkoutSession:在watchOS 2中关闭屏幕时未获得心率的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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