Caleb Caleb - 1 year ago 167
Swift Question

Location permission check and authorization

I want my program to display the users location on the map. It was working at first then randomly stopped so i added the code below to try to fix it but I'm having problems. Thanks in advance!

override func viewDidLoad()
self.locationManager.delegate = self
self.locationManager.desiredAccuracy = kCLLocationAccuracyBest
if CLLocationManager.locationServicesEnabled()

let status: CLAuthorizationStatus = CLLocationManager.authorizationStatus()
if status == CLAuthorizationStatus.NotDetermined
} else {

print("locationServices disenabled")
self.mapView.showsUserLocation = true
mapView.delegate = self

Answer Source

You required to call,


as well


to use location smoothly in forground also!!!

and you should not need two instance to call startupdatinglocation. keep one. you should use instance or global variable instead of local to get location throughout the scope.

Update :

You have to set two keys in info.plist like, NSLocationAlwaysUsageDescription and NSLocationWhenInUseUsageDescription. You can keep it's value as blank. But must provide this keys.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download