【问题标题】:Why requestWhenInUseAuthorization doesn't prompt the user for access to the location?为什么 requestWhenInUseAuthorization 不提示用户访问该位置?
【发布时间】:2015-10-28 23:50:03
【问题描述】:

在我的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];
}

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

【问题讨论】:

  • 另外,不建议您按照您的方式检查操作系统版本。最好使用if([locationManager respondsToSelector:@selector(requestWhenInUseAuthorization:)])

标签: objective-c xcode ios8 cllocationmanager


【解决方案1】:

您可能需要更新您的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>

您可能需要自定义和拼写检查 info.plist 文件中 shipping the code 之前的字典条目的字符串。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2023-01-09
    • 1970-01-01
    • 2012-11-29
    • 2019-02-02
    • 1970-01-01
    • 2023-02-11
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多