0
我想獲取我的位置,以便檢查我距離某個經度和緯度有多遠。Swift沒有達到LocationManager功能
出於某種原因,程序從未到達LocationManager函數,我想抓住我的座標。
我已經在info.plist中設置了正確的屬性,並且應用程序確實要求獲得許可。如果您使用的是iOS 8.0及更高版本,你需要開始更新位置之前,要求准予
didFailWithError Error Domain=kCLErrorDomain Code=0 "(null)"
import UIKit
import CoreLocation
import MapKit
class ViewController: UIViewController, CLLocationManagerDelegate {
var locationManager:CLLocationManager = CLLocationManager()
override func viewDidLoad() {
super.viewDidLoad()
locationManager.desiredAccuracy = kCLLocationAccuracyBest
locationManager.delegate = self
locationManager.requestWhenInUseAuthorization()
locationManager.startUpdatingLocation()
print("location on")
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
func locationManager(manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {
print("REACHED FUNCTION")
}
}
如果執行'的LocationManager(_:didFailWithError :) '它去那裏,而不是,如果是的話,什麼是錯誤? –
[CLLocationManager didUpdateLocations未被調用]可能的重複(http://stackoverflow.com/questions/26201471/cllocationmanager-didupdatelocations-not-being-called) – Vizllx
所以我得到了這個錯誤:didFailWithError錯誤域= kCLErrorDomain代碼= 0「 (null)「 – js091514