Joker
Joker

Reputation: 167

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?"); }

Upvotes: 2

Views: 6058

Answers (4)

MobileMon
MobileMon

Reputation: 8661

Specify both NSLocationAlwaysUsageDescription and NSLocationWhenInUseUsageDescription in your plist:

enter image description here

Also in code, request authorization:

if ([self.locationManager respondsToSelector:@selector(requestWhenInUseAuthorization)]) { // or requestAlwaysAuthorization
    [self.locationManager requestWhenInUseAuthorization]; // or requestAlwaysAuthorization
}
[self.locationManager startUpdatingLocation];

Upvotes: 1

János
János

Reputation: 35114

Need include MapKit.framework from Capabilities:

enter image description here

Upvotes: 2

McFish
McFish

Reputation: 39

I had the same problem, and my code (viewdidupdate method) was missing this:

_mapView.delegate = self;

For some reason the app worked in ios 7 without the line, but in ios 8.1 didUpdateUserLocation was never called.

Upvotes: 1

Rob
Rob

Reputation: 438162

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?

Upvotes: 2

Related Questions