Shows user location cannot be located using a map on ios8.
In xcode6, the positioning method of the apple map has been modified, and it used to be unavailable.
Error Description: Trying to start MapKit location updates without prompting for location authorization. Must call-[CLLocationManager requestWhenInUseAuthorization] or-[CLLocationManager requestAlwaysAuthorization] first.
Solution:
XXX.info under Supporting Files. in plis, two String fields, NSLocationAlwaysUsageDescription or NSLocationWhenInUseDescription, can be added. The value can be null or set to YES. However, I still cannot solve the problem and finally found the problem, that is, info. plist also needs to contain the Array field Supported interface orientations. Then run the command to solve the problem.
Code processing:
locationManager = [[CLLocationManager alloc] init]; locationManager.delegate = self; locationManager.desiredAccuracy=kCLLocationAccuracyBest; if([locationManager respondsToSelector:@selector(requestWhenInUseAuthorization)]) { [locationManager requestWhenInUseAuthorization]; } [locationManager startUpdatingLocation];
Another one:
-(Void) locationManager :( CLLocationManager *) manager didChangeAuthorizationStatus :( clthorizationstatus) status {if ([locationManager respondsToSelector: @ selector (requestWhenInUseAuthorization)] & amp; status! = Kclthorizationstatusnotdetermined & status! = Kclthorizationstatusauthorizedwheninuse) | (! [LocationManager respondsToSelector: @ selector (requestWhenInUseAuthorization)] & status! = Kclthorizationstatusnotdetermined & status! = Kclthorizationstatusauthorized) {NSString * message = @ "the location service is not currently enabled on your mobile phone. To enable the location service, go to settings to enable the location service "; UIAlertView * alertView = [[UIAlertView alloc] initWithTitle: @ "cannot be located" message: message delegate: nil cancelButtonTitle: @ "OK" failed: nil]; [alertView show];} else {[locationManager startUpdatingLocation];}
The above line is iOS 8 or above, and the second line is iOS 7 or below. kclthorizationstatusauthorized is completely unavailable in iOS 8.
Other places:
Clthorizationstatus status = [CLLocationManager authorizationStatus]; if (status = kclthorizationstatusauthorizedwheninuse | status = kclthorizationstatusauthorized) {// start locating} else {// warning}
Code modification snippets come from this: http://blog.dreambreakerx.com/tag/ios/