I am working on an iOS tracer. It must run and receive locations even if the app is not in foreground, i.e. I use the background mode "Location updates". However, it would be fine to safe battery if possible. Especially, there is no need to receive locations if the device does not move.
distanceFilter
on CLLocationManager
instance but it does not save power, it just reduces the number of location updates.pausesLocationUpdatesAutomatically
set to YES
(it is turned on by deafult) but if the app is in background and the location updates are paused, the app is suspended and does not wake up even if the device starts to move again.Is there a way to save battery when I need to get location in background? The flag pausesLocationUpdatesAutomatically
is very close to what I am looking for but suspending the app in background is a show stopper for me.
What you looking for is 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.
ex;
[locationManager allowDeferredLocationUpdatesUntilTraveled:100.0f timeout:CLTimeIntervalMax];
So basically it will save some processing power by sending the location updates as an collection of location after specific time rather than firing the location update callback every time device register a movement.
And you can recieve the location update via the follwing callback method;
-(void)locationManager:(CLLocationManager *)manager didFinishDeferredUpdatesWithError:(NSError *)error