如果手表应用程序进入后台或停用,有没有办法获取传感器数据? [英] Is there any way of fetching sensors data if watch app goes in background or de-activated?
问题描述
我正在开发手表应用扩展,其中我正在以最大 100HZ 的频率从所有传感器(加速度计、计步器、陀螺仪、气压计、位置、心率等)收集数据,但我面临传感器停止提供的问题以下场景中的数据:
I am working on watch app extension in which I am collecting the data from all sensors (Accelerometer, pedometer, gyroscope, barometer, location, heart rate etc) in maximum of 100HZ frequency, but I am facing problem with sensors stop giving data in following scenarios:
- 如果我放下手臂,传感器会工作几秒钟,直到我再次抬起手腕,传感器才会提供数据.
- 代码执行在任何时间点都会停止,因此我们无法获取数据.
所以我使用了 CMSensorRecorder
类,但只有这个类不能满足我们的要求.
So I used CMSensorRecorder
class but only this class can not fulfil our requirement.
那么有什么方法可以独立于 WKInterfaceController
的活动/取消激活状态来获取传感器数据?如果应用程序处于前台状态(活动状态或非活动状态),我必须获取数据.
so what is the way to get sensor data independent of active/de-activate state of WKInterfaceController
?
I have to fetch data if app is in foreground state, either active state or de-active state.
推荐答案
启用位置背景模式并设置 CLLocationManager.allowsBackgroundLocationUpdates = true
将使您的应用在后台记录传感器数据.
Enabling location background mode and setting CLLocationManager.allowsBackgroundLocationUpdates = true
will keep your app recording sensor data in the background.
这篇关于如果手表应用程序进入后台或停用,有没有办法获取传感器数据?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!