Skip to content

Instantly share code, notes, and snippets.

@emersonbroga
Created July 21, 2015 22:09
Show Gist options
  • Save emersonbroga/8e15e2c41f8c82a52073 to your computer and use it in GitHub Desktop.
Save emersonbroga/8e15e2c41f8c82a52073 to your computer and use it in GitHub Desktop.
//usage
// var alertController = self.createAlertForSettingsPanel("Please, check your settings")
// self.presentViewController(alertController, animated: true, completion: nil)
func createAlertForSettingsPanel(message: String, title: String = "My Title") -> UIAlertController
{
let alertController = UIAlertController( title: title, message: message, preferredStyle: .Alert);
let cancelAction = UIAlertAction(title: "Cancel", style: .Cancel, handler: nil)
alertController.addAction(cancelAction)
let openAction = UIAlertAction(title: "Open Settings", style: .Default) { (action) in
if let url = NSURL(string:UIApplicationOpenSettingsURLString) {
UIApplication.sharedApplication().openURL(url)
}
}
alertController.addAction(openAction);
return alertController;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment