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

时间:2018-10-19 15:32:18

标签: ios objective-c

如何在安装了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

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

1 个答案:

答案 0 :(得分:1)

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