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

Why requestWhenInUseAuthorization doesn't prompt the user for access to the location?

在我的 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 文件。这是一个 tutorial how to do it,又快又脏:

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

NSLocationWhenInUseUsageDescription

NSLocationAlwaysUsageDescription

您还需要为相应的定位方法申请授权,WhenInUseBackground。使用以下调用之一:

[self.locationManager requestWhenInUseAuthorization]
[self.locationManager requestAlwaysAuthorization]

还有一个 post 我觉得有帮助:

Location Services not working in iOS 8

此回答详情how to update your plist file

Add one of the following lines to your 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>

您可能希望在 shipping the code.

之前自定义 info.plist 文件中的字典条目的字符串并进行拼写检查