3

This afternoon I walked my iPhone 4 into the Apple Store to see if they could help with a problem I've been having. Battery life hasn't been AT ALL what it should be--the battery drops 50% sitting on my desk overnight. Crazy. So I suspect I've got a bum unit. Happens. No biggie.

My friendly genius pokes around my phone a bit, and points out that the Location Services pointer is lit in the top right corner of the screen. He gets into the location services settings. He notes that the following apps have the "got location data in the last few hours" flag lit: The Weather Channel, Showtimes, and two apps I wrote and am days away from submitting.

He turns off the sliders for each of those apps, and we see the top corner location services pointer turn off. Turning back on location services for EITHER of my apps makes it turn back on, and that's NOT the case for Weather Channel or Showtimes. But it's clear that turning on location services for my two apps fires up the device's location services. My lousy battery life is explained, but that's just the beginning of the mystery.

Here's the thing.... Neither of my apps are EVEN RUNNING at the time. They're not even backgrounded. They're OFF. I think they're both built in a debugging profile on my device at the moment, and they both do use Core Location. They're not suspended, they're just flat not running. And yet, turning on the slider in the location services control panel for either of them fires up location services in general.

So... What the heck is happening here? Neither of those apps are configured for background location. And... they're not IN the background! And since I've had location services turned off for them, there's no doubt my battery usage is way way down.

Adam Lear
  • 38,111
  • 12
  • 81
  • 101
Dan Ray
  • 21,623
  • 6
  • 63
  • 87
  • I noticed a similar problem when I left a traffic map app suspended one day (it uses CoreLoc). Battery was at 10% after a few hours. Are you sure they were not suspended? Otherwise sounds like an iOS bug. Apps are supposed to turn off CoreLocation when they get suspended (unless they specifically need it of course). – progrmr Jul 07 '10 at 01:15
  • @progrmr: Dead certain. Double-tapping the home button brought up an EMPTY list of backgrounded apps. No question my two apps weren't suspended. – Dan Ray Jul 07 '10 at 12:02

1 Answers1

3

The solution is at this thread in the Apple developer forum: https://devforums.apple.com/thread/58063?tstart=0

An earlier version of both of these apps had called [locationManager startMonitoringSignificantLocationChanges], and never called stopMonitoring.... Even though the current version of the apps didn't make that call, the OS still had the monitoring request "registered" to the apps (and was, in fact, relaunching them in the background as I drove around town!).

What I didn't know was that the monitoring request persists across launches--and across re-builds! I'd assumed that, like -startUpdatingLocation, the monitoring request would die with the process, but not so. The solution was to delete the apps from my device and reinstall.

Dan Ray
  • 21,623
  • 6
  • 63
  • 87
  • Yes, there's currently no way to switch off just the significant location updates for apps using it. Just killing them using the app switcher is not enough. So if you're using significant location updates in your app, make sure to provide some UI to switch off that service (or only enable it under certain circumstances). – Ortwin Gentz Nov 15 '10 at 10:03