Why the CLLocationManager delegate is not getting called in iPhone SDK 4.0?

I had a similar error, and is solved now. The issue is declaring locationManager variable locally. Declare it instead as a class variable and make sure it is retained either directly or via property retain (or strong if you use ARC). That solves the problem! The issue was de locationManager variable was released and never updated the delegate. Here the code:

.h file:

#import <UIKit/UIKit.h>
#import <MapKit/MapKit.h>
#import <CoreLocation/CoreLocation.h>


@interface MapViewController : UIViewController <MKMapViewDelegate, CLLocationManagerDelegate> {
@private
    MKMapView *_mapView;
    CLLocationManager *_locationManager;
}

@property(nonatomic, strong) CLLocationManager *locationManager;

@end

.m file:

self.locationManager = [[CLLocationManager alloc] init];
_locationManager.delegate = self;
_locationManager.desiredAccuracy = kCLLocationAccuracyBest;
[_locationManager startUpdatingLocation];

I hope it helps.

Leave a Comment