2

I have been using the location class as a delegate class and using my AppDelegate to update the location. I need the location on two cases: first at the time when he first signed into my application and then the next case is when he come from background. I am using UILocation like this in the first case:

    locationController = [[UILocation alloc] init];
    locationController.delegate = self;
    locationController.locationManager.desiredAccuracy = kCLLocationAccuracyBest;
    locationController.locationManager.distanceFilter = kCLDistanceFilterNone;
    [locationController.locationManager startUpdatingLocation]; 

and in the second case simply:

[locationController.locationManager startUpdatingLocation]

in my delegate method:

- (void)locationUpdate:(CLLocation *)location

In my delegate class I am doing this:

[locationController.locationManager stopUpdatingLocation]; 

after taking the lattitude and longitude. But it still updates after calling this.

I tried

    locationController.locationManager=nil;
    locationController.locationManager.delegate=nil

after stopping the update. But after this when I call startUpdateLocation, my delegate method is not called. Can anybody point me in what I am going wrong?

Shekhar Gupta
  • 6,206
  • 3
  • 30
  • 50
hacker
  • 8,919
  • 12
  • 62
  • 108
  • Why do you setup locationController.locationManager=nil; locationController.locationManager.delegate=nil; Just simply call stopUpdatingLocation and it should work fine. –  Aug 12 '13 at 11:52

1 Answers1

0

The problem is most probably not in the other code you provided. It is possible that you intialize locationController twice, this way you leak a CLLocationManager that keeps on updating as it does not receive the stopUpdatingLocation message. You should use the debugger to figure this out. Also, placing log messages in strategic points of the code is very helpful.

To avoid such double initializations, ensure that such value assignments are happening only in the init method.

allprog
  • 16,540
  • 9
  • 56
  • 97
  • (id) init { self = [super init]; if (self != nil) { locationManager = [[CLLocationManager alloc] init]; locationManager.delegate = self; // send loc updates to myself } return self; } what is wrong with this??? – hacker Aug 12 '13 at 12:11
  • The code in your post does not correspond to anything like this :) – allprog Aug 12 '13 at 12:30