ios – CLLocationManager在后台运行和省电

我正在研究iOS跟踪器.即使应用程序不在前台,它也必须运行和接收位置,即我使用后台模式“位置更新”.但是,如果可能的话,安全电池会很好.特别是,如果设备不移动,则不需要接收位置.

>我试图在CLLocationManager实例上设置distanceFilter,但它不能节省电力,只是减少了位置更新的次数.
>我无法手动停止并启动位置管理器,因为如果在后台,应用程序将被暂停.
>我尝试使用位置管理器,pausesLocationUpdatesAutomatically设置为YES(由deafult打开)但如果应用程序在后台并且位置更新暂停,则应用程序暂停,即使设备启动也不会唤醒再搬一次

当我需要在后台获取位置时,有没有办法节省电池?标志pausesLocationUpdatesAutomatically非常接近我正在寻找的,但暂停应用程序在后台是一个显示阻止我.

解决方法

你要找的是 this
- allowDeferredLocationUpdatesUntilTraveled:timeout:

If your app is in the background and the system is able to optimize
its power usage,the location manager tells the GPS hardware to store
new locations internally until the specified distance or timeout
conditions are met. When one or both criteria are met,the location
manager ends deferred locations by calling the
locationManager:didFinishDeferredUpdatesWithError: method of its
delegate and delivers the cached locations to the
locationManager:didUpdateLocations: method.

前;

[locationManager allowDeferredLocationUpdatesUntilTraveled:100.0f timeout:CLTimeIntervalMax];

因此,基本上它将通过在特定时间之后将位置更新作为位置集合发送而不是在每次设备注册移动时触发位置更新回调来节省一些处理能力.

您可以通过以下回调方法接收位置更新;

-(void)locationManager:(CLLocationManager *)manager didFinishDeferredUpdatesWithError:(NSError *)error

以上是来客网为你收集整理的ios – CLLocationManager在后台运行和省电全部内容,希望文章能够帮你解决ios – CLLocationManager在后台运行和省电所遇到的程序开发问题。

如果觉得来客网网站内容还不错,欢迎将来客网网站推荐给程序员好友。