2016-03-08 77 views
0

我已經設置了NSLocationAlwaysUsageDescriptionNSLocationWhenInUseUsageDescriptioninfo.plist,當應用程序想要使用位置服務時會顯示警報,但警報只顯示一段時間,而我無法點擊在這個警報。此警報自動消失!在iOS 9中的位置服務許可提醒

func showLocation(sender: UIButton) 
    { 
     let manager = CLLocationManager() 
     manager.delegate = self 
     if CLLocationManager.authorizationStatus() != CLAuthorizationStatus.AuthorizedAlways 
     { 
      manager.requestWhenInUseAuthorization() 
     } 
     manager.startUpdatingLocation() 
    } 
    func locationManager(manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) { 
     for location in locations { 
      print("The location is (location)") 
     } 
    } 
+0

檢查這一步一步,看看你是否正確使用它。 http://matthewfecher.com/app-developement/getting-gps-location-using-core-location-in-ios-8-vs-ios-7/ – UlyssesR

+0

在你的方法'alertView.dismissWithClickedButtonIndex (0,animated:true)' –

+0

請提供一些代碼 –

回答

2
self.locationManager = [[CLLocationManager alloc]init]; 
if ([CLLocationManager authorizationStatus] == kCLAuthorizationStatusNotDetermined) 
{ 
    if([[NSBundle mainBundle] objectForInfoDictionaryKey:@"NSLocationWhenInUseUsageDescription"] && [self.locationManager respondsToSelector:@selector(requestWhenInUseAuthorization)]){ 
     [self.locationManager requestWhenInUseAuthorization]; 
    } 
} 
else if([CLLocationManager authorizationStatus] == kCLAuthorizationStatusDenied) 
{ 
    //Location Services is off from settings 

} 
else if([CLLocationManager authorizationStatus] == kCLAuthorizationStatusRestricted) 
{ 

} 

嘗試下面的代碼。它爲我工作

+1

你是對的,CLLocationManager的實例必須是類級別的。並感謝您編寫代碼的框架。 – YunjieJi

+0

M很感激能夠幫助你:) –