我跟隨了蘋果開發者guide on location services。Xcode 8 iOS模擬器在我的Swift 3項目中沒有提示位置服務授權
我已經包括info.plist
密鑰值對:
鍵:Privacy - Location Always Usage Description
值:The application myTestApp needs access to location services even in the background
我已創建的CLLocationManager
實例作爲視圖控制器的類變量:
var locationManager = CLLocationManager()
我有一些代碼在視圖控制器viewDidLoad()
功能分配當前狀態的代表和檢查:
override func viewDidLoad() {
super.viewDidLoad()
locationManager.delegate = self
locationManager.desiredAccuracy = kCLLocationAccuracyKilometer
let status = CLLocationManager.authorizationStatus()
switch status {
case .denied, .restricted, .notDetermined, .authorizedWhenInUse :
print("The switch detected a state other than always")
locationManager.requestAlwaysAuthorization()
default:
print("Services Authorized")
}
然而,當我建立,使小的變化不提示用戶的訪問後,運行應用程序,甚至更糟的是,當它有時會工作時,它認爲用戶位於大西洋中緯度:0.0和長:0.0。
在我需要做的代碼之外有什麼東西可以重新創建授權應用程序然後看到它縮放到真實位置的用戶體驗嗎?
因爲這是一次性事件,所以您會認爲您可以刪除該應用程序並重新安裝它。這是行不通的。即使應用程序被刪除,iOS也會保留約1天的權限。它這樣做是爲了讓用戶刪除應用程序並重新安裝,而無需再次批准權限。 – ryantxr
@ umar-farooque和@ryantxr感謝您的幫助。除了您提供的用於獲取位置服務的答案之外,我還發現您可以在sim菜單欄中單擊'Simulator-> Reset Content&Settings',它將清除所有應用程序授權,以便您可以獲得完整的模擬的安裝和授權過程。 – ZacSketches
@ZacSketches是的,它會重置模擬器並刪除已安裝的應用程序及其設置。 –