19

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?

jimmym715
  • 1,512
  • 1
  • 16
  • 25
Andy
  • 446
  • 4
  • 9
  • 1
    @GregularExpressions - that sounds right. I don't believe that the GPS hardware could do much of anything in the first second after power-up. The receiver has to acquire a complete message frame from several satellites to calculate its position and the GPS signal bandwidth/bitrate is very low, (it has to be else small low-power receivers would be impossible). Even if signaled to shut down, the GPS system probably runs until it has acquired one fix before turning off. – Martin James Apr 08 '12 at 11:21
  • ..and the receivers in those low-power GPS chips are rubbish anyway. – Martin James Apr 08 '12 at 11:23
  • 2
    Did you solve your problem? – knagode Dec 16 '12 at 12:07
  • It didn't solve the problem and it's still an ongoing piece of research. What I do seem to have established is this process stops the iPhone going into deep sleep and it's not my connecting to the GPS which is causing the problem directly but all the other processes (such as mail, icloud, etc) keep running at full power. – Andy Jul 10 '13 at 09:01
  • 2
    @Andy: Did you come to a solution after 2 years :) ? Thanks . – androniennn Aug 17 '15 at 11:22

1 Answers1

2

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.