iOS 8 requestWhenInUseAuthorization no Popup [英] iOS 8 requestWhenInUseAuthorization no Popup

查看:181
本文介绍了iOS 8 requestWhenInUseAuthorization no Popup的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图让我的AppProject iOS 8准备就绪。我读了很多关于

  [_ locationManager requestWhenInUseAuthorization]; 

和plist中的条目

  NSLocationWhenInUseUsageDescription 

所以我改变了所有必要的代码行。 >

它工作正常,但现在我已经从我的iOS 7基础中再次复制我的项目以包含新功能。但是,当我对iOS8位置隐私进行更改时,弹出窗口不再出现。



我的代码一直工作,直到我复制。

 <?xml version =1.0encoding =UTF-8?> 
<!DOCTYPE plist PUBLIC - // Apple // DTD PLIST 1.0 // ENhttp://www.apple.com/DTDs/PropertyList-1.0.dtd\">
< plist version =1.0>
< dict>
< key> NSLocationWhenInUseUsageDescription< / key>
< string> tolle sache< / string>
< key> CFBundleDevelopmentRegion< / key>
< string> en< / string>
< key> CFBundleExecutable< / key>
< string> $ {EXECUTABLE_NAME}< / string>
< key> CFBundleIdentifier< / key>
< string> fapporite。$ {PRODUCT_NAME:rfc1034identifier}< / string>
< key> CFBundleInfoDictionaryVersion< / key>
< string> 6.0< / string>
< key> CFBundlePackageType< / key>
< string> BNDL< / string>
< key> CFBundleShortVersionString< / key>
< string> 1.0< / string>
< key> CFBundleSignature< / key>
< string> ????< / string>
< key> CFBundleVersion< / key>
< string> 1< / string>
< / dict>
< / plist>

这里是我的电话

   - (instancetype)initWithCoder:(NSCoder *)coder 
{
self = [super initWithCoder:coder];
if(self){

_UserLocation = [[CLLocation alloc] init];
_locationManager = [[CLLocationManager alloc] init]; //初始化locationManager
_locationManager.delegate = self;
_locationManager.desiredAccuracy = kCLLocationAccuracyBest; //设置精度
[_locationManager requestWhenInUseAuthorization]; // iOS 8必须为
[_locationManager startUpdatingLocation]; //请求位置更新

NSLog(@passed initwithcode);

}
返回自我;
}

如何解决这个问题?

解决方案



lockquote
NSLocationWhenInUseUsageDescription(String - iOS)描述了
为什么应用程序在前台运行
时正常访问用户的位置。当您的应用使用位置
服务直接跟踪用户的当前位置时,请添加此密钥。此密钥
不支持使用位置服务监控区域或使用重要位置更改服务监控
用户的位置。
系统在请求使用位置服务许可的情况下在用户
中显示的警报面板中包含此键值。



这个键是当您使用CLLocationManager类的requestWhenInUseAuthorization
方法请求对
位置服务的授权时需要。 如果您在调用
requestWhenInUseAuthorization方法时没有包含此密钥,则该密钥不存在,
系统将忽略您的请求。



此密钥在iOS 8.0及更高版本中受支持。如果Info.plist文件
包含此密钥和NSLocationUsageDescription密钥,则
系统将使用此密钥并忽略NSLocationUsageDescription密钥。

阅读它 here 。我发现将此密钥添加到您的info.plist最简单的方法是右键单击您的info.plist并选择
$ b

打开为 - >源代码



,然后在结尾 < / dict>< / plist>

 < key> NSLocationWhenInUseUsageDescription< / key> 
< string>< / string>

如果您想要,您可以在< string>< ; / string> ,它描述了用户为什么要使用他/她的位置。此文本将显示在警报的默认文本下。


I tried to make my AppProject iOS 8 ready. I had read a lot about

[_locationManager requestWhenInUseAuthorization];

and the entry in plist

NSLocationWhenInUseUsageDescription

So I changed all the necessary code lines.

It works fine, but now I have copied my project again from my iOS 7 base to include new features. But when I make the changes for the iOS8 Location Privacy the Popup doesn't appear anymore.

My code worked until I copied.

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
    <dict>
        <key>NSLocationWhenInUseUsageDescription</key>
        <string>tolle sache </string>
        <key>CFBundleDevelopmentRegion</key>
        <string>en</string>
        <key>CFBundleExecutable</key>
        <string>${EXECUTABLE_NAME}</string>
        <key>CFBundleIdentifier</key>
        <string>fapporite.${PRODUCT_NAME:rfc1034identifier}</string>
        <key>CFBundleInfoDictionaryVersion</key>
        <string>6.0</string>
        <key>CFBundlePackageType</key>
        <string>BNDL</string>
        <key>CFBundleShortVersionString</key>
        <string>1.0</string>
        <key>CFBundleSignature</key>
        <string>????</string>
        <key>CFBundleVersion</key>
        <string>1</string>
    </dict>
</plist>

and here is my call

- (instancetype)initWithCoder:(NSCoder *)coder
{
    self = [super initWithCoder:coder];
    if (self) {

        _UserLocation = [[CLLocation alloc]init];
        _locationManager = [[CLLocationManager alloc]init]; // initializing locationManager
        _locationManager.delegate = self;
        _locationManager.desiredAccuracy = kCLLocationAccuracyBest; // setting the accuracy
        [_locationManager requestWhenInUseAuthorization]; // iOS 8 MUST
        [_locationManager startUpdatingLocation];  //requesting location updates

        NSLog(@"passed initwithcode");

    }
    return self;
}

How can I fix this?

解决方案

From the documentation

NSLocationWhenInUseUsageDescription (String - iOS) describes the reason why the app accesses the user’s location normally while running in the foreground. Include this key when your app uses location services to track the user’s current location directly. This key does not support using location services to monitor regions or monitor the user’s location using the significant location change service. The system includes the value of this key in the alert panel displayed to the user when requesting permission to use location services.

This key is required when you use the requestWhenInUseAuthorization method of the CLLocationManager class to request authorization for location services. If the key is not present when you call the requestWhenInUseAuthorization method without including this key, the system ignores your request.

This key is supported in iOS 8.0 and later. If your Info.plist file includes both this key and the NSLocationUsageDescription key, the system uses this key and ignores the NSLocationUsageDescription key.

Read about it here.

I find that the easiest way to add this key to your info.plist is to right click you info.plist and choose

Open As->Source Code

and then add the following in the end before </dict></plist>

<key>NSLocationWhenInUseUsageDescription</key>
<string></string>

If you want you can add a text in between <string></string> that describes to the user why you want to use his/hers location. This text will show up under the default text in the alert.

这篇关于iOS 8 requestWhenInUseAuthorization no Popup的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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