Reputation: 167
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
Reputation: 8661
Specify both NSLocationAlwaysUsageDescription and NSLocationWhenInUseUsageDescription in your plist:
Also in code, request authorization:
if ([self.locationManager respondsToSelector:@selector(requestWhenInUseAuthorization)]) { // or requestAlwaysAuthorization
[self.locationManager requestWhenInUseAuthorization]; // or requestAlwaysAuthorization
}
[self.locationManager startUpdatingLocation];
Upvotes: 1
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
Reputation: 438162
A couple of thoughts:
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.
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.
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.
Have you implemented locationManager:didFailWithError:
? Does it report anything?
Have you implemented locationManager:didChangeAuthorizationStatus:
? Are you getting this called with a successful authorization status?
Upvotes: 2