15

Here's my situation. I'm developing an iPhone application that uses Core Location to determine the device's location. There is an icon: the Location Services Icon, that appears in the device's status bar. I know enough to say that the purpose of the icon is to tell the user that Location Services are currently being used by something. To the perceptive user, this means decreased battery life. For that reason, I want to be sure that the icon is displayed only when Location Services are actually being employed by my app.

Enter confusion. We, as developers, do not get access to the status bar via the official SDK. This means that the OS will display that icon automatically based on the behavior of the app. Try as I might, I cannot find a clear definition of what exactly causes that icon to show up.

As it stands, the icon appears before my app delegate gets control, and stays visible as long as the app is installed, running or not. This is clearly the worst case possible, and it made me doubt my use of CLLocationManager. I would elaborate on my use, but as an extreme case I tried removing the CoreLocation framework (and the MapKit framework, which I suspect also uses CoreLocation), and all code relating to location. The app still caused the icon to appear and stay until I deleted the app. I then made a brand new app, and made no changes except to change the app identifier to match the identifier of my app. The icon still appeared. I changed the identifier to use the identifier of one of my apps that did not use location, and the icon did not appear. I did make sure to reset the device during this testing.

This issue is really killing me. I cannot imagine what the application ID has to do with the Location Services icon, but I see no other cause for its persistence. It seems like a Red Herring hiding the real issue, but I'm at a loss as to the real issue.

Matt Wilding
  • 20,115
  • 3
  • 67
  • 95
  • Are you starting location updates as soon as your app launches, or sometime afterward (like after a button press)? – sudo rm -rf Dec 10 '10 at 22:47
  • I'm starting them in the applicationDidBecomeActive: delegate method. So, as soon as the app launches. – Matt Wilding Dec 10 '10 at 23:04
  • Check out my edited answer. Unfortunately you're out of luck in terms of the icon not showing, though it doesn't necessarily mean the battery is being drained at a higher rate. – Matthew Frederick Dec 10 '10 at 23:08
  • Yeah, I've read that the presence of the icon doesn't actually mean that Location Services are actively running, and I'm confident that my simplistic use of CLLocationManager is correct. Battery life aside, it is still an unfortunate and frustrating miscommunication to the user. – Matt Wilding Dec 10 '10 at 23:16

3 Answers3

22

Here's an update and a solution I've come to after some fiddling. Since my problem was clearly an issue with the OS making some connection between my app's ID and the Location Services icon, I tried resetting the device's location warnings, which I did not originally know I could do. For the curious, this can be accomplished through the Settings app, then General > Reset > Reset Location Warnings. After making this reset and upon reinstalling the app, it again requested to use Location Services. Now, the icon appears precisely on startUpdatingLocation and disappears precisely on stopUpdatingLocation, exactly as I originally intended.

I have no idea what initially caused this condition, and I have little doubt that the condition itself is an OS bug, as indicated by Matthew Frederick, but, at least in my case, the condition is curable.

Matt Wilding
  • 20,115
  • 3
  • 67
  • 95
  • Ah, forgot to mention that in my answer: for some resetting the warnings will solve the problem, but not for everyone. No idea why, but I know for an iPhone 3GS of mine running OS 4.0 it took a complete device wipe to solve it, something I can't suggest to my customers. Very glad it solved it for you, though! – Matthew Frederick Dec 11 '10 at 00:30
  • Thanks for posting all this. I just noticed similar behavior in my app. – Oscar Jun 16 '11 at 06:42
5

There's a known bug that's causing this problem. I reported it to Apple a couple of months ago and was informed that it was a dupe of a known problem. Unfortunately it doesn't appear to have been fixed.

I first discovered it when I saw the symbol appear (and my app showing as having permission to use location info in the Settings app) simply by installing my app on a device that no longer had the app installed, not having even run it.

For whatever reason the device keeps a reference to the app having once received permission for location services.

Worse, if the app actually received permission in the past, then gets uninstalled, then an updated version of the app is installed, not only does the icon appear but the upgraded app no longer actually receives location information because the app never gets to ask the OS for location permission. It's effectively permanently denied.

Very frustrating for me and a small number of my users.

Matthew Frederick
  • 22,245
  • 10
  • 71
  • 97
  • Indeed, I'm seeing similar behavior. It seems that simply installing any app with the same application identifier is enough to cause the icon to appear. Thanks for the info. – Matt Wilding Dec 10 '10 at 23:09
  • See my answer to my own question. I now believe that your small number of frustrated users can solve their issue with the same steps I followed to solve mine. – Matt Wilding Dec 11 '10 at 00:23
  • Any chance of a link or bug id for the known issue? – Roger Mar 16 '11 at 13:01
  • 1
    @Roger - From the email notifying me of the dupe: "This is a follow up to Bug ID# XXXXXXX. After further investigation it has been determined that this is a known issue, which is currently being investigated by engineering. This issue has been filed in our bug database under the original Bug ID# 8364797. The original bug number being used to track this duplicate issue can be found in the State column, in this format: Duplicate/OrigBug#." (I Xed out my bug number to avoid future confusion; anyone submitting should reference the original.) – Matthew Frederick Mar 16 '11 at 15:42
1

You haven't enabled the location option in the UIBackgroundModes key of your app's .plist, have you?

grahamparks
  • 16,130
  • 5
  • 49
  • 43