2017-07-18 57 views
0

彈出詢問位置沒有顯示出來,或者當它顯示出來後,它在幾秒鐘後消失,位置只有在經歷設置和設置允許定位服務時才起作用。我認爲這可能是一個問題,實際彈出窗口。定位不起作用

let locationManager = CLLocationManager() 
    let authStatus: CLAuthorizationStatus = 
CLLocationManager.authorizationStatus() 

    if authStatus == .notDetermined { 
     locationManager.requestWhenInUseAuthorization() 
    } 

    if authStatus == .denied || authStatus == .restricted { 
     showLocationServicesDeniedAlert() 
     return 
+0

您需要確保它是從主線程調用的。 – Swinny89

回答

1

locationManager可能不是本地變量,此代碼才能正常工作。在授權提示出現後,您創建的CLLocationManager實例即被刪除。刪除locationManager實例後,iOS將取消位置授權提示。

確保它是您的視圖控制器或應用程序委託類的成員變量。