我試圖讓我的AppProject iOS 8準備就緒。我讀了很多關於iOS 8 requestWhenInUseAuthorization no Popup
[_locationManager requestWhenInUseAuthorization];
和plist中
NSLocationWhenInUseUsageDescription
所以我改變了所有必要的代碼行的條目。
它工作正常,但現在我已經從我的iOS 7基地再次複製我的項目,以包括新功能。但是,當我對iOS8位置隱私進行更改時,Popup不再顯示。
我的代碼工作,直到我複製。
<?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;
}
我該如何解決這個問題?
這是我的主要問題。添加說明後,對話框彈出並立即消失。修復需要兩個更改:確保在viewWillAppear:或更高版本中請求授權,並確保存儲對CLLocationManager的引用。如果你不這樣做,它會被釋放,對話框消失。 – robotspacer
甚至可以將其添加到viewDidLoad中,但它對於保持對CLLocationManager的引用很重要。 – OutOnAWeekend
所以(只是爲了完整性),爲了保持引用,我使用了一個強修飾符的屬性:'@property(強,非原子)CLLocationManager * locationManager;'神聖的貓,@robotspacer'' –