You are missing two things. First, you have to ask for permission using requestAlwaysAuthorization
or requestWhenInUseAuthorization()
. So your viewDidLoad()
should be like this:
var locationManager = CLLocationManager()
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
locationManager.delegate = self
locationManager.desiredAccuracy = kCLLocationAccuracyBest
locationManager.requestAlwaysAuthorization()
locationManager.startUpdatingLocation()
}
Second, edit your Info.plist
as indicated here.