Locationservice Indicator stays "on"
Asked Answered
P

4

8

I have a created a small app which uses location services on the iPhone. All works well, except the fact, that sometimes, the small arrow in the info-bar stays active even if I explicitly kill the app. I use the background mode for locationservices, thus the appDelegate methods applicationWillResignActive, applicationDidEnterBackground, applicationWillEnterForeground and applicationDidBecomeActive are implemented but do not touch the location services (well - I need them in background mode).

In that configuration applicationWillTerminate is never called; I implemented all the cleanup cleanup as stopUpdatingLocation in dealloc, as I did not find any other place appropriate for this. But still - the indicator stays on.

Any ideas?

Patrilocal answered 2/2, 2011 at 8:6 Comment(0)
P
0

Ok, problem solved. The indicator will stay on until a new location is found. Then if everything else is correct, the indicator turns off.

Patrilocal answered 19/3, 2011 at 17:48 Comment(2)
Could you please clarify what you did to solve the problem? (or how this constitutes as a solution to your original problem)Perdure
as the general code infrastructure within the location manager changed a lot since iOS 5 I used at that time and I can not reconstruct now how I solved it three years ago.Patrilocal
B
13

I had the same problem - app leaving the location indicator on in the status bar.

My problem turned out to be that I had originally called the 'startMonitoringSignificantLocationChanges' method of CCLocationManager thinking that would give rough location info that I could up the resolution on when I really needed it.

Unfortunately once an app has called that method once, even if you then delete the app and re-install it it will always re-show the icon in the status bar until the app calls 'stopMonitoringSignificantLocationChanges' on CCLocationManager to unregister itself from the system - complete pain as I have to leave that code in until it has sorted itself out on the several people who were testing my app for me.

So if you get that icon stuck on with your app make sure you've matched any calls to 'startMonitoringSignificantLocationChanges' with a stop call.

Bader answered 11/5, 2011 at 10:22 Comment(1)
Wow I never would have figured this out... Very weird thing, right? Uninstalling an App should actually clear this flag from the OS, so to me this is an iOS bug...Lurie
W
3

if you started your location manager job with

[MyLocationManagerInstance startMonitoringForSignificantLocationChanges];

then you need to stop it with:

[MyLocationManagerInstance stopMonitoringForSignificantLocationChanges];

If you force the termination of the application, applicationWillTerminate isn't called, as, for the OS point of view, it appears as a SIGKILL.

Wickham answered 2/2, 2011 at 17:51 Comment(3)
... yes but where to put the call to this? If the only accepted way to finish an application is to kill it from the taskbar, but no method is being called in the app,it's difficult to clean up. And please note: I do not use startMonitoringForSignificantLocationChanges. I just use startUpdatingLocation. The app will continously be called on new locations in background.Patrilocal
I think this behavior is intended in the SDK. This way, if the application crashes or terminate, and then a CLLocation event triggers, your app relaunches with the appropriate key in the launchOptions dictionary. Have you checked on Apple devforums? (I don't think killing an app should be the only way to finish it, have you checked the rest of your code? The CLLocationManager instance you issue the calls should be the same)Wickham
For me, despite doing exactly this, the indicator would remain "on" in 95% of the cases. I discovered, however, that if you call [self.locationManager performSelector:(stopMonitoringForSignificantLocationChanges) withObject:nil afterDelay:1.] it would work every time. My guess is that any alloc/release of a locationManager or background/foreground of the app can make the call get "lost", so my solution essentially timeshifts the call.Burgher
I
1

I met a similar problem. The problem only happens on iPhone4, but works perfect on my 3GS. After looking into my code, I found that in my startUpdatingLocation method I used startUpdatingLocation and startMonitoringForRegion services, however, in my stopUpdatingLocation method I just stop updatingLocation service. I fixed this issue by turning off MonitoringForRegion as well.

#pragma mark -
#pragma mark Location methods
- (void)startUpdatingLocation
{

    [self.locationManager startUpdatingLocation];

    [self.locationManager startMonitoringForRegion:desRegion desiredAccuracy:50.0f];
}

- (void)stopUpdatingLocation
{
    [self.locationManager stopUpdatingLocation];

        //  !!!: fix location service indicator stuck issue
    [self.locationManager stopMonitoringForRegion:desRegion];
}
Izolaiztaccihuatl answered 8/6, 2011 at 9:55 Comment(0)
P
0

Ok, problem solved. The indicator will stay on until a new location is found. Then if everything else is correct, the indicator turns off.

Patrilocal answered 19/3, 2011 at 17:48 Comment(2)
Could you please clarify what you did to solve the problem? (or how this constitutes as a solution to your original problem)Perdure
as the general code infrastructure within the location manager changed a lot since iOS 5 I used at that time and I can not reconstruct now how I solved it three years ago.Patrilocal

© 2022 - 2024 — McMap. All rights reserved.