Ayoola Solomon Ayoola Solomon - 1 year ago 130
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

Answer Source

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);
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download