为什么requestWhenInUseAuthorization不提示用户访问该位置? [英] Why requestWhenInUseAuthorization doesn't prompt the user for access to the location?

查看:2291
本文介绍了为什么requestWhenInUseAuthorization不提示用户访问该位置?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的 viewDidLoad 方法中我有

  locationManager = [[ CLLocationManager alloc] init]; //初始化locationManager 
locationManager.delegate = self; //我们将locationManager的委托设置为self。
locationManager.desiredAccuracy = kCLLocationAccuracyBest;
[locationManager startUpdatingLocation];


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

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

解决方案

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



您需要做的是在Info.plist文件中添加以下密钥之一:

  NSLocationWhenInUseUsageDescription 

NSLocationAlwaysUsageDescription

你还需要请求相应位置方法的授权, WhenInUse 背景。使用以下调用之一:

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

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



< a href =https://stackoverflow.com/questions/24062509/location-services-not-working-in-ios-8>位置服务在iOS 8中无效



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


将以下行之一添加到info.plist



< pre class =lang-xml prettyprint-override> < key> NSLocationWhenInUseUsageDescription< / key>
< string>堆栈溢出的精神是编码器帮助编码器< / string>

< key> NSLocationAlwaysUsageDescription< / key>
< string>我在堆栈溢出方面比其他任何东西都学到了更多< / string>


你可能想要自定义和拼写检查字符串在发送代码之前,在info.plist文件中的字典条目。


In my viewDidLoad method I have

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];
    }

And the request is called, but the user is not prompted? Why?

解决方案

You probably need to update your plist file. Here's a tutorial how to do it, quick & dirty:

You need to do is to add one of the following keys to your Info.plist file:

NSLocationWhenInUseUsageDescription

NSLocationAlwaysUsageDescription

You also need to request authorization for the corresponding location method, WhenInUse or Background. Use one of these calls:

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

There's also a post that I found helpful:

Location Services not working in iOS 8

This answer details 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>

You'll probably want to customize and spell-check the strings of the dictionary entry that goes in the info.plist file before shipping the code.

这篇关于为什么requestWhenInUseAuthorization不提示用户访问该位置?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆