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

时间:2015-08-06 01:37:51

标签: 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;
[locationManager startUpdatingLocation];


if([[[UIDevice currentDevice] systemVersion] floatValue] >= 8.0) {
    [locationManager requestWhenInUseAuthorization];
}

请求被调用,但是没有提示用户?为什么呢?

1 个答案:

答案 0 :(得分:258)

您可能需要更新plist文件。这是tutorial how to do it,快速&脏:

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

NSLocationWhenInUseUsageDescription

NSLocationAlwaysUsageDescription

您还需要为相应的地理位置方法WhenInUseBackground申请授权。使用以下电话之一:

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

还有一篇我觉得有用的帖子:

Location Services not working in iOS 8

此答案详情how to update your plist file

  

将以下其中一行添加到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文件中字典条目的字符串。