iOS 8 requestWhenInUseAuthorization 没有弹出

时间:2023-03-22
本文介绍了iOS 8 requestWhenInUseAuthorization 没有弹出的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

问题描述

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

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

[_locationManager requestWhenInUseAuthorization];

和plist中的条目

NSLocationWhenInUseUsageDescription

所以我更改了所有必要的代码行.

So I changed all the necessary code lines.

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

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>

这是我的电话

- (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?

推荐答案

来自文档

NSLocationWhenInUseUsageDescription (String - iOS) 描述了应用程序在运行时正常访问用户位置的原因在前台.当您的应用使用位置信息时包含此密钥直接跟踪用户当前位置的服务.这把钥匙不支持使用位置服务监控区域或监控使用重大位置更改服务的用户位置.这系统在显示的警报面板中包含此键的值请求使用位置服务的权限时的用户.

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.

使用 requestWhenInUseAuthorization 时需要此密钥CLLocationManager 类的方法来请求授权位置服务.如果在您调用requestWhenInUseAuthorization 方法不包括这个键,系统会忽略您的请求.

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.

iOS 8.0 及更高版本支持此键.如果您的 Info.plist 文件包括这个键和 NSLocationUsageDescription 键,系统使用此键并忽略 NSLocationUsageDescription 键.

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.

阅读它这里.

我发现将此键添加到 info.plist 的最简单方法是右键单击 info.plist 并选择

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

打开为->源代码

然后在最后before </dict></plist>

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

如果你愿意,你可以在 <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 没有弹出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

上一篇:如何在 Google Maps for Android API v2 上显示我的位置 下一篇:如何持续追踪安卓手机的位置?

相关文章