Shows user location cannot be located using a map on ios8.

Source: Internet
Author: User

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/

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.