So I have a map search function that has a text field. I set up an UIAlertController there, and it works fine, i.e. it brings up an alert when there's not location nearby.
I have a current location button, but I want to perform action only if the user allows for current location status to be turned on. Otherwise, I want to display an alert. This is where my error comes in. The frustrating part is that I have a print statement when access is not granted, and it displays that, and skips the alert entirely. I tried removing the statements and just the alert come up without any other code in the button... Still nothing. What's going on?
@IBAction func currentLocationBtn(sender: UIBarButtonItem) {
checkLocationAuthorizationStatus()
if self.locationAuthorized {
locationManager.desiredAccuracy = kCLLocationAccuracyBest
self.currentLocation = CLLocation(latitude: locationManager.location.coordinate.latitude, longitude: locationManager.location.coordinate.longitude)
} else {
println("Current Location is disabled")
let alertController = UIAlertController(title: "Current Location Turned Off", message:
"Sorry, you need to turn on Current Location to use this feature", preferredStyle: UIAlertControllerStyle.Alert)
alertController.addAction(UIAlertAction(title: "Dismiss", style: UIAlertActionStyle.Default,handler: nil))
}
}