Search code examples
iosobjective-ccllocationmanagercllocationuserlocation

didUpdateUserLocation not called in iOS 8.1


Since I updated to iOS SDK 8 and 8.1, there have been many problems, including that the method of CLLocationManager didUpdateLocations is no longer called.

Here the code: In viewDidLoad:

locationManager = [[CLLocationManager alloc] init];
locationManager.delegate = self;
locationManager.desiredAccuracy = kCLLocationAccuracyHundredMeters; // 100 m
if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 8.0) {
    [locationManager requestAlwaysAuthorization];
}
[locationManager startUpdatingLocation];

The method:

- (void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations{ NSLog(@"Call?"); }

Solution

  • A couple of thoughts:

    1. Are you testing this on simulator or on device? You must test this on actual device. FWIW, didUpdateLocations works fine on my iOS 8.1 device.

    2. Make sure that you specified the NSLocationAlwaysUsageDescription string or else the app won't present the authorization message, and you won't be authorized.

      Obviously, if you don't need "always usage", you should just requestWhenInUseAuthorization and then you must specify NSLocationWhenInUseUsageDescription string.

    3. Have you checked [CLLocationManager authorizationStatus]? I do that before I even try to authorize or start location services, because if it's either kCLAuthorizationStatusDenied or kCLAuthorizationStatusRestricted, the location services won't work until the user goes to settings and remedies that. You may want to present them a message to that effect if you get either of these authorization codes.

    4. Have you implemented locationManager:didFailWithError:? Does it report anything?

    5. Have you implemented locationManager:didChangeAuthorizationStatus:? Are you getting this called with a successful authorization status?