核心位置管理器不会要求授权

时间:2016-03-14 21:24:46

标签: ios objective-c ios9 core-location

在一个简单的项目中,我实例化一个核心位置管理器:

- (void)viewDidLoad {
[super viewDidLoad];
self.locationManager = [[CLLocationManager alloc] init];
self.locationManager.desiredAccuracy =
kCLDistanceFilterNone;
self.locationManager.delegate = self;
if([CLLocationManager locationServicesEnabled]) {
    // Location Services Are Enabled
    switch([CLLocationManager authorizationStatus]) {
        case kCLAuthorizationStatusNotDetermined:
            NSLog(@"1");
            [self.locationManager requestWhenInUseAuthorization];
            NSLog(@"requested auth");
            break;
        case kCLAuthorizationStatusRestricted:
            NSLog(@"2");
            break;
        case kCLAuthorizationStatusDenied:
            NSLog(@"3");
            break;
        case kCLAuthorizationStatusAuthorized:
            NSLog(@"4");
            break;
    }
} else {
    // Location Services Disabled
}
[self.locationManager startUpdatingLocation];

}

我在info.plist中也有相应的键:

enter image description here

基于此代码的日志输出是:

[233:5927] 1
[233:5927] requested auth

但我没有得到授权请求......

没有错误,没有位置更新(如果我实现委托回调)

1 个答案:

答案 0 :(得分:0)

愚蠢的错误,在错误的plist文件中添加了键(测试一个而不是app一个)