2017-10-19 79 views
4

iOS的對話框提示和消失後半秒:位置的權限對話框顯示並立即消失

 let locationManager = CLLocationManager() 
     switch CLLocationManager.authorizationStatus() { 
     case .authorizedWhenInUse: 
      print("In Use \(locationManager.location?.description)") 
     case .denied, .restricted: 
      print("denied") 
     case .notDetermined: 
      locationManager.requestWhenInUseAuthorization() 
     case .authorizedAlways: 
      print("always \(locationManager.location)") 
     } 

我不知道這是否是相關的,但我使用SWReavealViewController。 Xcode9,編譯爲iOS 8.0,這兩個模擬器和真實設備

+0

該代碼在哪裏執行? – RaffAl

+0

我在不同的地方嘗試過 – gutte

回答

5

locationManager變量不會活過它的定義(其中的代碼片段居住功能)的範圍,所以它被釋放之前,用戶可以響應到對話框。

如果你將let locationManager = CLLocationManager()移動到一個類變量,它應該堅持下去。