位置权限的iOS alertview不会popup

我刚开始我的项目为iOS 8,我跑了太多的问题,我不能让问题popup权限。 我在info.plist中添加了以下内容

<key>NSLocationWhenInUseUsageDescription</key> <string>The spirit of stack overflow is coders helping coders</string> <key>NSLocationAlwaysUsageDescription</key> <string>I have learned more on stack overflow than anything else</string> 

这是我的代码:

 @interface ViewController () <MKMapViewDelegate> @property (nonatomic, strong) UIPopoverController* userDataPopover; @property (weak, nonatomic) IBOutlet MKMapView *mapView; @property (strong, nonatomic, retain) CLLocationManager *locationManager; @end @implementation ViewController -(CLLocationManager *)locationManager { if(!_locationManager) _locationManager = [[CLLocationManager alloc]init]; return _locationManager; } - (void)viewDidLoad { [super viewDidLoad]; self.mapView.delegate = self; [self.locationManager requestWhenInUseAuthorization]; //[self.locationManager requestAlwaysAuthorization]; [self.locationManager startUpdatingLocation]; self.mapView.showsUserLocation = YES; [self.mapView showsUserLocation]; [self.mapView setMapType:MKMapTypeStandard]; [self.mapView setZoomEnabled:YES]; [self.mapView setScrollEnabled:YES]; } - (void)mapView:(MKMapView *)mapView didUpdateUserLocation:(MKUserLocation *)userLocation { MKCoordinateRegion region = MKCoordinateRegionMakeWithDistance(userLocation.coordinate, 800, 800); [self.mapView setRegion:[self.mapView regionThatFits:region] animated:YES]; } 

确保您的视图控制器实现CLLocationManagerDelegate并导入#import CoreLocation / CoreLocation.h

 - (void)viewDidLoad { [super viewDidLoad]; [self setLocationManager:[[CLLocationManager alloc] init]]; if([self.locationManager respondsToSelector:@selector(requestWhenInUseAuthorization)]){ [self.mapview setShowsUserLocation:NO]; [self.locationManager setDelegate:self]; [self.locationManager requestWhenInUseAuthorization]; } else{ //Before iOS 8 [self.mapview setShowsUserLocation:YES]; } } 

添加此方法来侦听AuthorizationStatus更改

 -(void)locationManager:(CLLocationManager *)manager didChangeAuthorizationStatus:(CLAuthorizationStatus)status { if (status == kCLAuthorizationStatusDenied) { // permission denied [self.mapview setShowsUserLocation:NO]; } else if (status == kCLAuthorizationStatusAuthorized) { // permission granted [self.mapview setShowsUserLocation:YES]; } } 

最后确保你的plist有以下的条目由Sanne指出

 <key>NSLocationWhenInUseUsageDescription</key> <string>The spirit of stack overflow is coders helping coders</string> <key>NSLocationAlwaysUsageDescription</key> <string>I have learned more on stack overflow than anything else</string> 

它新的ios 10现在在plist文件中添加位置权限

如果没有在plist中添加权限,那么权限popup不显示

在plist中添加以下权限

1.隐私 – 在使用中的位置使用说明

2.Privacy – 位置始终使用说明