IOS8 problem locating Solution

Source: Internet
Author: User

IOS8 problem locating Solution
1. Modify info

New keys: NSLocationAlwaysUsageDescription and NSLocationWhenInUseUsageDescription are added. The values of these two keys are used to describe the instructions for using and locating during application use. These instructions are displayed in user settings.

The new key-value pairs in info are as follows:


For application instructions, see:

2. CLLocationManager Initialization

IOS8CLLocationManager adds the instance methods requestWhenInUseAuthorization and requestAlwaysAuthorization, which must be called as needed during initialization.

 

If ([CLLocationManager locationServicesEnabled]) {self. locationManage = [[CLLocationManager alloc] init]; self. locationManage. delegate = self; // The positioning frequency. The number of meters is used to locate the self. locationManage. distanceFilter = 200; // sets the positioning precision self. locationManage. desiredAccuracy = kCLLocationAccuracyBestForNavigation; // kCLLocationAccuracyBest; // start tracking and locating [self. locationManage startUpdatingLacation]; if (SYSTEM_VERSION> = 8.0) {// [self. locationManage requestWhenInUseAuthorization]; // always // or [self. locationManage requestAlwaysAuthorization]}
3. Proxy (CLLocationManagerDelegate)

// Locating failed

-(Void) locationManager :( CLLocationManager *) manager didFailWithError :( NSError *) error

{

[MBHUDUntil hideAllHUDForView: self. window];

If (! [SharedData multicast instance]. isMB = NO ){

[MBHUDUntil showhudtow.wwithtext: @ "map locating failed. Please confirm that you have allowed this program to enable the locating service"];

}

}

 

// Trace and locate the proxy method, which is executed every time the location changes (as long as the corresponding location is located)

-(Void) locationManager :( CLLocationManager *) manager didUpdateLocations :( NSArray *) locations {

// If real-time location is not required, even if the location Service is Disabled

[_ LocationManager stopUpdatingLocation];

}

Add the following proxy method:

- (void)locationManager:(CLLocationManager *)manager didChangeAuthorizationStatus:(CLAuthorizationStatus)status{  switch (status) {    case kCLAuthorizationStatusNotDetermined:      if ([self.locationManage respondsToSelector:@selector(requestAlwaysAuthorization)])      {        [self.locationManage requestWhenInUseAuthorization];      }      break;    default:    break;  }}

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.