IOS 11+ 定位服务授权失败,即使 key 存在

标签 ios objective-c

如何在安装了 IOS 12 并将目标版本设置为 11 的 iPhone 上使用定位服务?我正在研究原型(prototype),因为我记得定位服务有点麻烦。我有以下代码:

-(id) init {
if (self = [super init]) {
    manager = [[CLLocationManager alloc] init];
    [manager setDelegate:self];
    [manager setDesiredAccuracy:kCLLocationAccuracyNearestTenMeters];
    [manager setDistanceFilter:50];
    [manager requestWhenInUseAuthorization];
    switch ([CLLocationManager authorizationStatus]) {
        case kCLAuthorizationStatusNotDetermined:
            [self presentAlertForLocationServices];
            break;
        case kCLAuthorizationStatusRestricted:
            NSLog(@"Location restricted");
            break;
        case kCLAuthorizationStatusDenied:
            NSLog(@"Location Denied");
            break;
        case kCLAuthorizationStatusAuthorizedAlways:
            [manager startUpdatingLocation];
            NSLog(@"Updating locations...");
            break;
        case kCLAuthorizationStatusAuthorizedWhenInUse:
            [manager startUpdatingLocation];
            NSLog(@"Updating locations...");
            break;
    }
}
return self;

我有以下键:

<key>NSLocationWhenInUseUsageDescription</key>
<string>$(PRODUCT_NAME) always uses location </string>

<key>NSLocationAlwaysAndWhenInUseUsageDescription</key>
<string>$(PRODUCT_NAME) needs location in order to find nearby points of interest</string>

但是,我在运行该应用程序时遇到以下错误:此应用程序已尝试在没有使用说明的情况下访问隐私敏感数据。应用程序的 Info.plist 必须包含一个“NSLocationWhenInUseUsageDescription”键和一个字符串值,向用户解释应用程序如何使用此数据

我尝试了 3 个不同的 key (NSLocationWhenInUseUsageDescription、NSLocationAlwaysAndWhenInUseUsageDescription、NSLocationAlwaysInUseUsageDescription)的各种组合以及 2 个不同的授权请求,但没有成功。我正在使用 XCode 10.0 (10A255)。任何指导将不胜感激。我确实发现 Apple 存在按键无法正常工作的问题,但那是一年多以前的事了,我确信问题已得到解决,尽管我不知道答案。

最佳答案

检查以确保您编辑了正确的 Info.plist - 您的应用真正使用的那个。它是您在该应用程序目标的build设置中指向的那个吗?

关于IOS 11+ 定位服务授权失败,即使 key 存在,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52895608/

相关文章:

Objective-C:我认为 UILabel "stuck"

iphone - 使用点击手势的 locationInView 和 CGPoint

iphone - 从文档目录读取 plist 文件时为空

objective-c - 闲聊和 ObjectiveC 中的消息传递是否与参数中具有值类型(结构)的调用方法相同?

ios - 根据内容动态改变弹出框的大小

ios - navigationBar 下的 UIToolBar 没有工具栏在滚动时移动

ios - 在 MVVM 中处理来自 UITableViewCell 的 Action

objective-c - 操作系统 X : how to watch socket read events with NSRunLoop?

iphone - 从网站到 iPhone 应用程序的内容

ios - 调整约束高度后,Swift 约束无法移回屏幕底部