为什么requestWhenInUseAuthorization不提示用户访问该位置?

spe*_*f10 69 xcode objective-c cllocationmanager ios8

在我的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];
}
Run Code Online (Sandbox Code Playgroud)

并且调用了请求,但是没有提示用户?为什么?

Adr*_*ian 267

您可能需要更新您的plist文件.这是一个教程如何做,快速和脏:

您需要做的是将以下键之一添加到Info.plist文件中:

NSLocationWhenInUseUsageDescription

NSLocationAlwaysUsageDescription
Run Code Online (Sandbox Code Playgroud)

您还需要请求相应位置方法的授权,WhenInUseBackground.使用以下电话之一:

[self.locationManager requestWhenInUseAuthorization]
[self.locationManager requestAlwaysAuthorization]
Run Code Online (Sandbox Code Playgroud)

还有一篇帖子我觉得很有帮助:

位置服务在iOS 8中不起作用

此答案详细说明了如何更新plist文件:

将以下行之一添加到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>
Run Code Online (Sandbox Code Playgroud)

您可能希望在发送代码之前自定义并拼写检查info.plist文件中字典条目的字符串.