繁体   English   中英

即使存在密钥,IOS 11+位置服务授权也会失败

[英]IOS 11+ Location Services Authorization fails even though keys exist

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

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

但是,运行该应用程序时出现以下错误: This app has attempted to access privacy-sensitive data without a usage description. The app's Info.plist must contain an “NSLocationWhenInUseUsageDescription” key with a string value explaining to the user how the app uses this data This app has attempted to access privacy-sensitive data without a usage description. The app's Info.plist must contain an “NSLocationWhenInUseUsageDescription” key with a string value explaining to the user how the app uses this data

我尝试了3种不同的键(NSLocationWhenInUseUsageDescription,NSLocationAlwaysAndWhenInUseUsageDescription,NSLocationAlwaysInUseUsageDescription)以及2种不同的授权请求,并以多种方式组合在一起而没有运气。 我正在使用XCode 10.0(10A255)。 任何指导将不胜感激。 我确实发现Apple存在密钥无法正常工作的问题,但是那是一年多以前的事了,我确定问题已经解决,尽管我不知道答案。

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM