我刚开始我的iOS 8项目,遇到了一个问题,就是无法弹出请求权限的问题。我已经在我的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];
}