-2
问一个简单的项目,我实例化一个核心位置经理:核心位置管理不授权
- (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
,但我没有得到任何授权的请求......
没有错误,没有位置更新(如果我实现委托回调)
好吧,所以第一个返回YES和第二个NO。我如何改变第二个? –
对不起,但你必须更具体。我像这样检索它: [CLLocationManager authorizationStatus] –
所以,状态是kCLAuthorizationStatusNotDetermined。我如何强制用户确定它?我尝试了多次卸载并重新安装应用程序... –