Objective c 为什么在未使用授权时请求';是否提示用户访问该位置?
在我的Objective c 为什么在未使用授权时请求';是否提示用户访问该位置?,objective-c,xcode,ios8,cllocationmanager,Objective C,Xcode,Ios8,Cllocationmanager,在我的viewDidLoad方法中 locationManager = [[CLLocationManager alloc]init]; // initializing locationManager locationManager.delegate = self; // we set the delegate of locationManager to self. locationManager.desiredAccuracy = kCLLocationAccuracyBest; [locat
viewDidLoad
方法中
locationManager = [[CLLocationManager alloc]init]; // initializing locationManager
locationManager.delegate = self; // we set the delegate of locationManager to self.
locationManager.desiredAccuracy = kCLLocationAccuracyBest;
[locationManager startUpdatingLocation];
if([[[UIDevice currentDevice] systemVersion] floatValue] >= 8.0) {
[locationManager requestWhenInUseAuthorization];
}
并调用请求,但不提示用户?为什么?您可能需要更新
plist
文件。这是一个快速而肮脏的例子:
您需要做的是将以下键之一添加到Info.plist文件中:
NSLocationWhenInUseUsageDescription
NSLocationAlwaysUsageDescription
在使用或后台时,您还需要请求相应定位方法的授权。使用以下调用之一:
[self.locationManager requestWhenInUseAuthorization]
[self.locationManager requestAlwaysAuthorization]
我还发现有一个帖子很有帮助:
此答案详细说明:
在info.plist中添加以下行之一
n不使用时的位置说明
堆栈溢出的精神是程序员帮助程序员
N位置始终使用说明
我学到的关于堆栈溢出的知识比其他任何东西都多
您可能需要自定义和拼写检查info.plist文件中的字典条目的字符串。此外,不建议以您现在的方式检查操作系统版本。如果([locationManager响应选择器:@selector(RequestWhenUseAuthorization:)]),最好使用if(