Here is a Swift2 version that worked for me including an Alert that instructs the user in what to do when the settings opens.
func initLocationManager() {
locationManager = CLLocationManager()
locationManager.delegate = self
locationManager.desiredAccuracy = kCLLocationAccuracyBest
locationManager.requestAlwaysAuthorization()
// If there isn't a Lat/Lon then we need to see if we have access to location services
// We are going to ask for permission to use location if the user hasn't allowed it yet.
let status = CLLocationManager.authorizationStatus()
if(status == CLAuthorizationStatus.NotDetermined || status == CLAuthorizationStatus.Denied) {
//println(locationManager)
// check that locationManager is even avaiable. If so, then ask permission to use it
if locationManager != nil {
locationManager.requestAlwaysAuthorization()
//open the settings to allow the user to select if they want to allow for location settings.
let alert = UIAlertController(title: "I Can't find you.", message: "To let my App figure out where you are on the map click 'Find Me' and change your location to 'Always' and come back to MyMobi.", preferredStyle: UIAlertControllerStyle.Alert)
alert.addAction(UIAlertAction(title: "No Thanks", style: UIAlertActionStyle.Default, handler:nil))
alert.addAction(UIAlertAction(title: "Find Me", style: UIAlertActionStyle.Default, handler: {
(alert: UIAlertAction!) in
UIApplication.sharedApplication().openURL(NSURL(string: UIApplicationOpenSettingsURLString)!)
}))
self.presentViewController(alert, animated: true, completion: nil)
}
}
}