Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Reducing iOS Background Location Battery Usage

I'm working on an iOS app that ideally needs to run the location services in the background. I've tested the significant location, and that isn't accurate enough. The accurate location is perfect, but this consumes far too much battery life to make the app viable.

To get around this battery issue I thought I'd found a solution that uses NSTimer inside UIApplication:beginBackgroundTaskWithExpirationHandler:. This turns the location on and then instantly off again, which triggers a location update and resets the backgroundTimeRemaining.

However, this solution still drains a lot of battery – 15%-20% every 3-4 hours – even when the location is only turned on for one second every 9 minutes. The app is not running anything else in the background aside from this one timer. I've even tried releasing all of the views when entering the background to make sure there is nothing sitting and consuming the battery.

Checking inside instruments, I found the app is using 0.0% of the CPU and 14 MB of memory while in this waiting state. I'm at a bit of a loss at this point as to the cause, especially since running the GPS for 1 second every 540 seconds does not provide an appreciable reduction in battery consumption, compared to running it 24/7.

I've started compiling the following questions, which might contribute to the problem, and I'm hoping somebody has an answer or an idea...

  • Does running an app in this way stop the phone from entering some sort of low power mode?

  • Does starting the GPS use huge amounts of power?

  • Does the GPS keep running for a period of time even after turning off?

like image 375
Andy Avatar asked Apr 08 '12 10:04

Andy


People also ask

Does keeping location on in iPhone drain the battery?

Location services and the GPS can use up plenty of battery life. Depending on how you use your device, you may not need location services on most of the time. So turning them off, and only turning them on when you need them can save plenty of battery life.

How do I stop my background from draining my battery?

Let's get into the best battery improvements. The simplest way to keep background apps in check is using Android's Adaptive Battery feature. Turn it on by going to Settings > Battery > Adaptive preferences and toggle Adaptive Battery on.

How do I reduce background usage on my iPhone?

Enable Low Power Mode. Your iPhone lets you know when your battery level goes down to 20%, and again at 10%, and lets you turn on Low Power Mode with one tap. Or you can enable it by going to Settings > Battery. Low Power Mode reduces display brightness, optimizes device performance, and minimizes system animations.


1 Answers

Yes, WWDC 2011 Session 312 "iOS Performance and Power Optimization with Instruments" covers this at about the 45 minute mark.

When you finish using the GPS it can remain active for up to 10 seconds, and active radios both wake the device and while active prevent the device from 'sleeping'.

You'll be able to see this using the 'Energy Diagnostics' template in Instruments.

like image 144
GregularExpressions Avatar answered Oct 18 '22 05:10

GregularExpressions