Lucien Lucien - 1 year ago 94
Objective-C Question

Location still monitoring after locationManager = nil and stopUpdatingLocation called

I'm trying a lot of things to stop the location update of my app but nothing seems work…

What I do (regard of the post : StopUpdatingLocation method not working for iOS5) :

// Initialise my locationManager and start monitoring :
locationManager = [[CLLocationManager alloc] init];
[locationManager startUpdatingLocation];

// .. Some code to use the coordinates that locationManager gives me.

// To stop monitoring :
locationManager = nil;


You have to know I placed
[locationManager stopUpdatingLocation];
in the method :

- (void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations


So the location is updated only 1 time (btw tell me if it's a good idea…).

I also tried to place
[locationManager stopUpdatingLocation];
just before
locationManager = nil;
in the main code, but the blue dot that gives me my location is still moving on my map in both cases…

I also set a timer which print the
locationManager
object in the console, and it gives me
(null)
meanwhile the blue dot is still moving on my iPhone 5 so I don't understand that…

Or maybe the dot is still moving because of another thing, but not because of locationManager update ?

I'm certainly missing something but I don't get what :/.

Thanks for ideas and help.

Answer Source

One possibility: The blue dot moving on your map is because you set the MKMapView's showsUserLocation to YES. It will track until you set it to NO.

Another possibility: This line is wrong:

locationManager = nil;

That does not stop monitoring, but it does cause you to be unable to refer to the location manager, so now you can't stop monitoring! Cut that line.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download