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; }}