12

I'm currently developing an iPhone application which needs location services for various use including AR.

I test everything on simulator and on my iPhone 3GS and everything went well.

I recently tested on iPhone4 and on iPad2 and the location service (the little icon in status bar) keeps displaying even when I manually kill the app! The only way to disable this icon is to manually stop the location service for my app in the settings.

Does anyone know something about this? If needed I can post my code.

Thank you in advance

Edit :

When I kill the application, go to location services, switch off my app the location icon disappears. But when I switch it back on, it reappears! Is that normal?

Jaffa
  • 12,442
  • 4
  • 49
  • 101

7 Answers7

9

I've found the answer! It came from region monitoring, which I enabled before, but removed all code using it weeks ago.

As I had already tested on the iPad, and even if I deleted and re-installed the app, the system seems to have kept information on region I monitored.

Thus, as described by the documentation, the iOS kept on locating for my App, just as startMonitoringSignificantLocationChanges.

Thanks for you answers, it gave me a better understanding of the location system and how to efficiently use it (in particular thanks to progrmr and Bill Brasky)

Community
  • 1
  • 1
Jaffa
  • 12,442
  • 4
  • 49
  • 101
  • 1
    This solved my problem. I had removed some significant change monitoring but still had the location monitoring appear to be active. Reseting location notifications in settings fixed the bug for me. – Kelend Nov 23 '11 at 17:35
  • 3
    I just wasted hours tracking down the same "feature" with significant change service. Just as you describe with region monitoring, I removed significant change service several versions ago, had completely uninstalled and reinstalled the app, and when I turned on standard location services on the current rendition of the app, and then turned it off, the location services icon would stay on. Obviously the significant change settings also persist despite uninstalling the app. I just called `stopMonitoringSignificantLocationChanges` once, and now all is well. Wow, that's frustrating. – Rob Feb 25 '13 at 17:30
  • Yes, thanks Apple for making good framework :) *irony* What iOS version are you testing on ? May be good to fill a radar – Jaffa Feb 25 '13 at 22:04
  • (watch this wonderful website: https://bugreport.apple.com/cgi-bin/WebObjects/RadarWeb.woa/59/wo/aumGtx93LqQzg707QVp0MM/9.66) – Jaffa Feb 25 '13 at 22:16
8

Sounds like you're app is going into the background and still using CLLocation. You can stop CLLOcationManager when you receive notification that you're app is resigning active, that's the best way. Then resume when it becomes active. The answer in this question show how to do that here

[EDIT] When your app goes into the background or resigns active for any reason (ie: phone call) you should stop location services at that time. You need to subscribe to the notifications and provide a method to stop and start location services, something like this:

-(void)appDidBecomeActiveNotif:(NSNotification*)notif
{
    [locationManager startUpdatingLocation];
}

-(void)appWillResignActiveNotif:(NSNotification*)notif
{
    [locationManager stopUpdatingLocation];
}

-(void)viewDidLoad
{
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(appDidBecomeActiveNotif:) name:UIApplicationDidBecomeActiveNotification object:nil];         
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(appWillResignActiveNotif:) name:UIApplicationWillResignActiveNotification object:nil]; 
}

-(void)dealloc
{
    [[NSNotificationCenter defaultCenter] removeObserver:self];
    [super dealloc];
}
Community
  • 1
  • 1
progrmr
  • 75,956
  • 16
  • 112
  • 147
  • Thank's for you answer, I added the CLLocationManager stopMonitoringSignificantLocationChanges in my Locator's dealloc method, but it still doesn't work! – Jaffa Sep 14 '11 at 13:54
  • dealloc is not the right place. You need to subscribe to the notifications. I've added more details to my answer. – progrmr Sep 14 '11 at 14:37
  • Thank's again, I've implemented your method but this still don't work! I added some log and the methods are called on the right moment, but the application keeps on locating – Jaffa Sep 14 '11 at 15:14
  • How do you really know it keeps on locating? I doubt it. Try killing it from the app history slider at the bottom. – progrmr Sep 15 '11 at 15:07
  • That's what I do... And I know it keeps locating because the localization indicator keeps on displaying – Jaffa Sep 15 '11 at 15:21
2

I have been battling with this problem for a while, and I think I've finally gotten to the bottom of it..

The reason that the location service doesn't stop when you ask it to is not because you haven't stopped it or released it properly. It's actually caused by releasing and re-allocating the CLLocationManager itself, in my experience.

If you have code which releases your CLLocationManager in applicationDidEnterBackground, and then you allocate a brand new one in applicationDidEnterForeground, etc., then you'll probably have this problem.

The solution is this:

  1. Only create your CLLocationManager object once, in applicationDidFinishLaunching.
  2. To start, call startUpdatingLocation, startMonitoringSignificantLocationChanges etc. as normal.
  3. To stop updates, call the appropriate stopUpdatingLocation, stopMonitoringSignificantLocationChanges etc. as normal.
  4. Never, ever release your CLLocationManager or set its' reference to nil (except possibly in applicationWillTerminate, but that probably won't make any difference).

This way, I went from having my app continue to use location services for up to 12 hours after putting my app away in the background, to the location services arrow disappearing within 10 seconds of backgrounding with this new approach.

Note: Tested on iPhone 4S running iOS 5.1.1. To get accurate results on your app's performance in this regard, make sure you go into Settings->Location Services->System Services and turn off the Status Bar Icon switch. That way, the status bar arrow will accurately reflect usage by apps alone.

Simon Tillson
  • 3,609
  • 1
  • 15
  • 23
2

I ran into this same exact issue when using the region monitoring tools. It didn't matter what I did to disable the regions, the arrow remained. I did finally solve the issue by cleaning up the calls to locationManager. If you are closing your view and don't need the location manager, set it to nil and/or release it. If you are monitoring location in the background, it will stay up there, but if not, make sure you are cleaning up all your location monitoring.

It seems like it is a bug, but as I found out, it is not. Just requires a bit more cleanup.

Bill Burgess
  • 14,054
  • 6
  • 49
  • 86
1

This is the solution which fixed this problem for me.

Just stop monitering location changes in

- (void) applicationDidEnterBackground: (UIApplication *)application
{
    [locationManager stopMonitoringSignificantLocationChanges];
    locationManager.delegate = nil;
}

not in applicationWillEnterForeground: .Still,it takes a few seconds to disappear locating icon.

I don't know why it isn't working in the latter method.

Li Fumin
  • 1,383
  • 2
  • 15
  • 31
  • 4
    Why can't I? The answered you marked works for you doesn't mean it definetly works for others.My post may not be useful for you, others may find this post useful. – Li Fumin Apr 12 '12 at 05:46
  • I agree with you, but you don't give a new answer, as what you said is already in the previous posts :) – Jaffa Apr 12 '12 at 10:23
1

Presumably this is so users don't need to stare at the bar to notice some mischievous app is using location services. That icon appears when you use any location services and remains for some indeterminate time afterwards.

This is intentional behavior Apple wants users to know which apps are using their locations. It seems this is sensitive data, wouldn't you agree?

EricLeaf
  • 892
  • 5
  • 12
  • The icon does not remain for "some indeterminate time". It remains as long as location is being used. Once you stop, the icon goes away immediately. – Bill Burgess Sep 21 '11 at 18:53
1

I've run into that problem a while ago and found it useful to apply only one method of applicationDelegate object

- (void)applicationWillEnterForeground:(UIApplication *)application;

If you'll stop your CLLocationManager from receiving updates inside that call, you'll be alright. Of course you'll need to start updating somewhere else, and - (void)applicationDidBecomeActive:(UIApplication *)application; will be a good choice. Also you need to note, that there are two methods of location awareness

  • the gps based -(void)start/stop_UpdatingLocation;

  • and the 3g/wi-fi based -(void)start/stop_MonitoringSignificantLocationChanges;

Vasily Kabunov
  • 6,511
  • 13
  • 49
  • 53
Ariel
  • 2,430
  • 1
  • 17
  • 20