1

I'm completely stumped with a problem using CoreLocation.

I've checked out some other questions and on Google but can't seem to find anyone with this particular problem I'm having.

I am utilizing CoreLocation in my App and when I call [manager startUpdatingLocation] then the little blue arrow on the status bar appears and the service begins and all is well.

In the app I have a UITabBarController, now only the first Tab makes use of CoreLocation so in my first Tab ViewController's viewDidDisappear method, I call [manager stopUpdatingLocation]

Now here is where things go wrong, If I manually just tap the different tabs then the little blue arrow disappears and re-appears as I go back and forth between the tabs as I would expect them to.

However, upon doing something on the first tab, it will automatically switch to another tab via [self.tabBarController setSelectedIndex:1], when this happens, the blue arrow on the status bar does NOT disappear, and even if I continuously go back and forth through the tabs, that arrow is now basically stuck there for as long as the app is active (It does disappear if the app goes into the background though, but will re-appear on any tab and stay stuck there as before if it becomes active again).

Now I thought, maybe changing the tabs programatically doesn't call viewDidDisappear, so I put a breakpoint there, but it does indeed get called.

Then I thought... Ok maybe if I call [manager stopUpdatingLocation] just before i call [self.tabBarController setSelectedIndex:1] that would fix the problem, but that didn't do anything either.

Now I'm lost for ideas and any help would be greatly appreciated.

P.S: I have tested to see if the CoreLocation delegate methods are still being called, and they don't seem to be called anymore unless the initial tab is open, so it does seem as though CoreLocation has stopped. However, from a user perspective this wouldn't seem to be the case.

EDIT: Seems like this might be a problem with some third party libraries, so isn't really something that can be answered

Jason
  • 519
  • 6
  • 14
  • Some similar questions have been asked recently perhaps one of them will help? [here](http://stackoverflow.com/q/8155456/154803) or [here](http://stackoverflow.com/q/7881743/154803) – progrmr Dec 03 '11 at 18:11

2 Answers2

2

The indicator won't disappear until you release the CLLocationManager.

EDIT: My initial answer was incorrect, the indicator should indeed disappear when stopUpdatingLocation is called.

EDIT 2: I created a basic test application, and calling stopUpdatingLocation in viewDidDisappear does cause the indicator to disappear in my case. Code from the first view controller is below:

- (void)viewDidAppear:(BOOL)animated {
    [super viewDidAppear:YES];

    if (locationManager == nil) {
        self.locationManager = [[[CLLocationManager alloc] init] autorelease];
        self.locationManager.delegate = self;
    }

    [self.locationManager startUpdatingLocation];
}

- (void)viewDidLoad {
    [super viewDidLoad];

    UIButton *button = [UIButton buttonWithType:UIButtonTypeRoundedRect];
    button.frame = CGRectMake(20, 20, 280, 40);
    [button setTitle:@"Go to Tab 2" forState:UIControlStateNormal];
    [button addTarget:self action:@selector(buttonTapped) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:button];
}

- (void)viewDidDisappear:(BOOL)animated {
    [super viewDidDisappear:animated];
    [self.locationManager stopUpdatingLocation];
}

- (void)buttonTapped {
    [self.tabBarController setSelectedIndex:1];
}
Can Berk Güder
  • 109,922
  • 25
  • 130
  • 137
  • In that case, why is it disappearing when I manually change tabs by tapping on them? – Jason Nov 29 '11 at 01:22
  • Thanks for the clarification... I just tried a few things and that didn't seem quite right. Thanks for trying to help anyway, much appreciated. – Jason Nov 29 '11 at 01:39
  • Thanks for that Can Berk, I'll try to create another application as well to see what happens. – Jason Nov 29 '11 at 01:52
  • Well I just tried a new application and it does indeed work... I get the feeling that something is conflicting with these Microsoft libraries I'm using which also make use of Core Location....damn.... – Jason Nov 29 '11 at 02:11
  • @Jason maybe it's the libraries that hang onto the location manager? – Can Berk Güder Nov 29 '11 at 02:18
  • Yes that is what I'm thinking... it is quite possible that is the case, although I can't see why they would need to... damn you Microsoft and your closed source code /*shakes fist/*, thanks for the help Can Berk – Jason Nov 29 '11 at 02:37
0

So the actual problem was related to closed source 3rd party libraries which I had no control of, so this question has no real answer

Jason
  • 519
  • 6
  • 14