CLLocationManager delegate doesn't get called when I return to a view from another view controller. But it works perfectly fine if the view controller loads without presenting another view controller.
For example, everytime if defaults.objectForKey("firstTimeUser") == nil {
is called and that view controller is dismissed, CLLocationManager delegate doesn't get called.
override func viewDidAppear(animated: Bool) {
super.viewDidAppear(true)
let defaults = NSUserDefaults.standardUserDefaults()
if defaults.objectForKey("firstTimeUser") == nil {
if let servicesController = self.storyboard?.instantiateViewControllerWithIdentifier("ServicesController") as? UITableViewController {
self.navigationController?.presentViewController(servicesController, animated: true, completion: nil)
}
defaults.setObject("set", forKey: "firstTimeUser")
defaults.synchronize()
} else {
getLocationData()
loadNewsData()
}
}
func getLocationData() {
self.locationManager.desiredAccuracy = kCLLocationAccuracyBest
self.locationManager.distanceFilter = 3000
self.locationManager.delegate = self
self.locationManager.requestWhenInUseAuthorization()
}
I believe it has something to do with LocationManager being called inside a class method rather than an instance method. Also tried setting LocationManager in the main_thread:
dispatch_async(dispatch_get_main_queue(), {
self.locationManager.desiredAccuracy = kCLLocationAccuracyBest
self.locationManager.distanceFilter = 3000
self.locationManager.delegate = self
self.locationManager.requestWhenInUseAuthorization()
})