2

I have an app where I need accurate location updates every K minutes -- even while in the background. Significant location-change updates are not sufficient for my needs, hence I need to use CLLocationManager's startUpdatingLocation method and keep it running forever.

I want to use as little power as possible while still getting my periodic location updates. It seems that the two options for saving power are (temporarily) setting the desiredAccuracy property of the CLLocationManager to the least-accurate setting (e.g. 3-miles), or to defer location updates via the allowDeferredLocationUpdates* method. However, these two techniques are mutually incompatible since deferred updates require a high accuracy setting (most accurate).

Does anyone know which approach saves more power, or if there is another way to minimize power usage while still getting periodic updates (even in the background).

Mike Curtiss
  • 1,838
  • 2
  • 17
  • 33
  • 1
    Very interested to hear what you decided to do with this? Currently I have a coarse setting (3km), run a "beginBackgroundTaskWithExpirationHandler" every 3 minutes (not sure if this will be OK with Apple?), check the accuracy returned - if it's not acceptable increase the desired accuracy and rinse/repeat until I get my location with the desired accuracy. – Shocks Mar 14 '14 at 15:05

2 Answers2

3

You should be doing both deferred updates and reduce desiredAccuracy.

And every K minutes, check the current CLLocation value, if its accuracy it acceptable, then use it. If not reduce the desiredAccuracy to 30m (or Best or whatever max is acceptable) for up to 30 seconds. This will turn on the GPS chip for 30 seconds, if you get an acceptable accuracy location, use that location and immediately put the desiredAccuracy back to 3000 (kCLLocationAccuracyThreeKilometers) until the next K minute period starts. If you don't get acceptable accuracy during that 30 seconds, too bad, use the best CLLocation that you got during that 30 sec period, go back to 3000m accuracy and try again in K minutes.

Be sure to read up on how to configure deferred updates. It's not easy to get them to work, but using that will allow you to wake the CPU only 1 during your 30 second time when the GPS is on instead of 30 times, saving lots of battery there too.

Deferred updates require iPhone 5 or later and iOS 6 or later. You can use deferredLocationUpdatesAvailable to determine if a device supports it.

Community
  • 1
  • 1
progrmr
  • 75,956
  • 16
  • 112
  • 147
0

Deferred updates uses vastly less power, but it requires hardware support so it isn't always available. It works by caching the location data in hardware and then passing it to your app all at one time (the power saving is in not activating the app frequently). It also offers time based configuration.

Monitoring for significant changes (startMonitoringSignificantLocationChanges) again uses less power by not using the GPS (using cell towers instead), so again it requires specific hardware support.

Simply setting the desired accuracy to low doesn't necessarily use either of the above features so you should check the device capability at runtime and use whichever features are available. AFAIK there are no statistics released for which of the hardware supported options uses less power.

Wain
  • 118,658
  • 15
  • 128
  • 151
  • The question is whether deferred updates are better than low-accuracy updates (or if there's some third option). Deferred updates save some power AFAICT, but my intuition is that they still take more power than low-accuracy updates since it requires the GPS to be powered-up. – Mike Curtiss Dec 09 '13 at 05:36
  • Deferred updates save a lot of power by not waking up the CPU every second. Yes, the GPS keeps running but it is still a **significant** improvement compared to not deferring updates. – progrmr Aug 22 '14 at 15:27