我的工作在一張銀行代碼爲iOS 8.我試圖做一些事情,涉及的位置,所以我已經實現了我迅速的視圖控制器文件中的以下內容:CLLocationManager授權問題的iOS 8
let locationManger:CLLocationManager = CLLocationManager()
var speedReceived:Double = 0
override func viewDidLoad() {
super.viewDidLoad()
locationManger.delegate = self
locationManger.desiredAccuracy = kCLLocationAccuracyBest
let authstate = CLLocationManager.authorizationStatus()
if(authstate == CLAuthorizationStatus.NotDetermined){
println("Not Authorised")
locationManger.requestWhenInUseAuthorization()
}
// Do any additional setup after loading the view, typically from a nib.
}
func locationManager(manager: CLLocationManager!, didUpdateLocations locations: [AnyObject]!){
var location:CLLocation = locations[locations.count - 1] as CLLocation
if(location.horizontalAccuracy > 0){
self.speedReceived = location.speed
println(self.speedReceived)
}
}
func locationManager(manager: CLLocationManager!, didFailWithError error: NSError!) {
println("Couldn't get your location")
}
但是,我似乎無法得到此代碼的工作。它不保存我的偏好位置使用。它甚至沒有提示我允許訪問位置。我曾嘗試更新我的info.plist。但它不起作用。順便說一句,如果我總是在模擬器的隱私設置中選擇,它會工作,如果我立即切換回應用程序。誰能幫忙?我確信這是問題所在,因爲我的控制檯上沒有授權。
任何幫助?
你說,你已經更新了的info.plist - 你雙重檢查您的項目? 「NSLocationWhenInUseUsageDescription」需要與描述您位置使用的字符串一起呈現。簡單的拼寫錯誤會阻止您的應用提示進行位置訪問。你也應該總是調用'locationManager.requestWhenInUseAuthorization()',而不僅僅是當你的狀態是未經授權的 – Paulw11