問題描述
我試圖讓我的 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 沒有彈出的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!