2016-03-14 83 views
-2

問一個簡單的項目,我實例化一個核心位置經理:核心位置管理不授權

- (void)viewDidLoad { 
[super viewDidLoad]; 
self.locationManager = [[CLLocationManager alloc] init]; 
self.locationManager.desiredAccuracy = 
kCLDistanceFilterNone; 
self.locationManager.delegate = self; 
if([CLLocationManager locationServicesEnabled]) { 
    // Location Services Are Enabled 
    switch([CLLocationManager authorizationStatus]) { 
     case kCLAuthorizationStatusNotDetermined: 
      NSLog(@"1"); 
      [self.locationManager requestWhenInUseAuthorization]; 
      NSLog(@"requested auth"); 
      break; 
     case kCLAuthorizationStatusRestricted: 
      NSLog(@"2"); 
      break; 
     case kCLAuthorizationStatusDenied: 
      NSLog(@"3"); 
      break; 
     case kCLAuthorizationStatusAuthorized: 
      NSLog(@"4"); 
      break; 
    } 
} else { 
    // Location Services Disabled 
} 
[self.locationManager startUpdatingLocation]; 

}

我也有在info.plist中相應的按鍵:

enter image description here

基於此代碼的日誌輸出爲:

[233:5927] 1 
[233:5927] requested auth 

,但我沒有得到任何授權的請求......

沒有錯誤,沒有位置更新(如果我實現委託回調)

+0

好吧,所以第一個返回YES和第二個NO。我如何改變第二個? –

+0

對不起,但你必須更具體。我像這樣檢索它: [CLLocationManager authorizationStatus] –

+0

所以,狀態是kCLAuthorizationStatusNotDetermined。我如何強制用戶確定它?我嘗試了多次卸載並重新安裝應用程序... –

回答

0

愚蠢的錯誤,添加在錯誤的plist文件的密鑰(測試一個而不是應用程序之一)