当App处于引导访问模式时,CLLocation Manager不会更新

我保持iPad的应用程序的指导访问。 当应用程序启动时,它使用CLLocationManager要求用户的当前位置。这是在正常模式下工作,并更新用户当前的位置。 但是在引导访问下, popup ("Allow to access your location")不显示, authorizationStatus始终为kCLAuthorizationStatusNotDetermined ,不更新用户的当前位置。 无法理解可能是什么问题。搜了很多,但找不到它。

 ViewController.m : - (void)viewDidAppear:(BOOL)animated { [appDelegate startLocation]; [self performSelector:@selector(CheckLocationManger) withObject:nil afterDelay:0.1]; } -(void)CheckLocationManger { AppAppDelegate *appDelegate=(AppAppDelegate*)[[UIApplication sharedApplication]delegate]; if(![CLLocationManager locationServicesEnabled]) { UIAlertView *alert1 = [[UIAlertView alloc] initWithTitle:@"Whoops we can't find you!" message:@"Location services are disabled" delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil]; if(activityIndictr) [activityIndictr stopAnimating]; [alert1 show]; return; } if([CLLocationManager locationServicesEnabled]) { if([CLLocationManager authorizationStatus]==kCLAuthorizationStatusDenied) { UIAlertView *alert1 = [[UIAlertView alloc] initWithTitle:@"Whoops we can't find you!"message:@"Location services are disabled. You can fix this by going to Settings > Privacy > Location" delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil]; if(activityIndictr) [activityIndictr stopAnimating]; [alert1 show]; return; } if([CLLocationManager authorizationStatus]==kCLAuthorizationStatusNotDetermined) //This is called { [self performSelector:@selector(CheckLocationManger) withObject:self afterDelay:0.1]; return; } } if(![self connected]) { UIAlertView *alert1 = [[UIAlertView alloc] initWithTitle:@"Network Error" message:@"Please verify that you have internet connectivity" delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil, nil]; if(activityIndictr) [activityIndictr stopAnimating]; [alert1 show]; [alert1 release]; return; } else { //continue further process } } AppDelegate.m - (void)startLocation { self.locationManager = [[[CLLocationManager alloc] init]autorelease]; self.locationManager.pausesLocationUpdatesAutomatically=NO; [self.locationManager setDelegate:self]; if([[[UIDevice currentDevice ]systemVersion] floatValue]>=8.0) { if ([self.locationManager respondsToSelector:@selector(requestWhenInUseAuthorization)]) { [self.locationManager requestWhenInUseAuthorization]; //is executed but popup never displays } } [self.locationManager startUpdatingLocation]; } 

任何build议将有所帮助。谢谢!

首先在您的.plist设置NSLocationWhenInUseUsageDescriptionNSLocationAlwaysUsageDescription

在你的class.h文件中添加CoreLocation.framework并导入 – > #import <CoreLocation/CoreLocation.h>然后将CLLocationManagerDelegate设置为你的类。

声明@property (strong, nonatomic) CLLocationManager *locationManager; 初始化locationManager并为其设置默认值。

 self.locationManager = [[CLLocationManager alloc] init]; self.locationManager.delegate = self; self.locationManager.pausesLocationUpdatesAutomatically = NO; [self.locationManager setDesiredAccuracy:kCLLocationAccuracyBestForNavigation]; [self.locationManager setDistanceFilter:200.0f]; if ([self.locationManager respondsToSelector:@selector(requestAlwaysAuthorization)]) // Or if ([self.locationManager respondsToSelector:@selector(requestWhenInUseAuthorization)]) [self.locationManager requestAlwaysAuthorization]; // Or [self.locationManager requestWhenInUseAuthorization]; [self.locationManager startUpdatingLocation]; 

实现CLLocationMAnager委托方法

 #pragma mark - Location Delegate - (void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations { NSLog(@"updated coordinate are %@", [locations lastObject]); CLLocation *currentLocation = [locations lastObject]; // Your code..... }