Ayoola Solomon Ayoola Solomon - 5 months ago 42
Swift Question

How do i open phone settings when a button is clicked ios

I am trying to implement a feature in an App that shows an alert when internet connection is not available.
The alert has two action OK and Settings, whenever a user clicks on settings i want to take them to the phone settings programmatically.

I am using Swift and Xcode-Beta


Using UIApplicationOpenSettingsURLString

override func viewDidAppear(animated: Bool) {
    var alertController = UIAlertController (title: "Title", message: "Go to Settings?", preferredStyle: .Alert)

    var settingsAction = UIAlertAction(title: "Settings", style: .Default) { (_) -> Void in
        let settingsUrl = NSURL(string: UIApplicationOpenSettingsURLString)
        if let url = settingsUrl {

    var cancelAction = UIAlertAction(title: "Cancel", style: .Default, handler: nil)

    presentViewController(alertController, animated: true, completion: nil);