Having some issues with my auth request method shown below:
func requestAuthorisation() {
if CLLocationManager.authorizationStatus() == .NotDetermined {
let locationPermissionRequest = UIAlertController.init(title: "Location services", message: "Some message, hidden for obvious reasons...", preferredStyle: .Alert)
let alwaysOnButton = UIAlertAction.init(title: "Always on (recommended)", style: .Default, handler: { (alert: UIAlertAction!) in
locationPermissionRequest.dismissViewControllerAnimated(true, completion: {
self.locationManager.requestAlwaysAuthorization()
})
})
let backgroundButton = UIAlertAction.init(title: "On when in use", style: .Default, handler: { (alert: UIAlertAction!) in
locationPermissionRequest.dismissViewControllerAnimated(true, completion: {
self.locationManager.requestWhenInUseAuthorization()
})
})
let noButton = UIAlertAction.init(title: "Off", style: .Destructive, handler: { (alert: UIAlertAction!) in
locationPermissionRequest.dismissViewControllerAnimated(true, completion: nil)
})
locationPermissionRequest.addActions(withActions: [alwaysOnButton, backgroundButton, noButton])
locationPermissionRequest.present(true, completion: nil)
}
}
The problem here is that when I tap the when in use button or the always button, their actions are invoked and the alert is dismissed but the location auth is never requested. I have put a breakpoint on the lines where the auth request is made and the methods are being invoked. Interestingly if I move the call to the auth methods out of their respective completion blocks then it works fine, but for my purposes I need them to not be invoked until my custom alert is dismissed.
Does anyone know why I am seeing this behaviour/know of a fix?
EDIT:
I just tried wrapping in a call to dispatch on the main thread as I had a sneaking suspicion it was a threading issue but alas, it is not.