![](/img/trans.png)
[英]how to programmatically open Settings > Privacy > Location Services in 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.