在一个简单的项目中,我实例化一个核心位置管理器:
- (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中也有相应的键:
基于此代码的日志输出是:
[233:5927] 1
[233:5927] requested auth
但我没有得到授权请求......
没有错误,没有位置更新(如果我实现委托回调)
答案 0 :(得分:0)
愚蠢的错误,在错误的plist文件中添加了键(测试一个而不是app一个)