我们的应用想要在后台访问加速度计数据。一种可能的实现方式是使用 Core Motion 进行加速度计读数 -
与
CLLocationManager* locationManager;
CMMotionManager* motionManager;
...
[motionManager startAccelerometerUpdatesToQueue: ... withHandler: ...]
在前台工作正常,但我发现在后台接收更新的唯一方法是将应用程序设置为允许在后台使用位置,然后调用
[locationManager startUpdatingLocation]
在 -applicationWillResignActive:
问题是,当我调用 startUpdatingLocation
时,会弹出一个窗口,其中包含文本 Turn On Location Services to Allow "app"to Determine Your Location
。
当然,无论是否启用定位服务,我都会收到加速度计读数,但弹出窗口很烦人,可能会让用户感到困惑。
在后台获取加速度计数据是否与尝试接收位置更新有些关联?
最佳答案
您可以在后台使用 startAccelerometerUpdatesToQueue
,这是您唯一需要满足的条件 — 使用任何后台模式让您的应用程序在后台运行(位置更新(您的情况)、播放、VoIP 或 BT4中央)。
关于iphone - iOS - 后台加速度计显示位置服务弹出窗口,但我们不需要位置服务,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19003360/