Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iOS 10 Open Settings Crash

So we are creating an iOS app that with the push of a button opens up the device's settings app. I have seen that the method has slightly changed with iOS 10 and Swift 3 so I am using a conditional to check which iOS version the user is on before executing the code.

if let settingsUrl = URL(string: UIApplicationOpenSettingsURLString) {

    if #available(iOS 10.0, *) {

        // iOS 10.0.

        UIApplication.shared.open(settingsUrl, options: [:], completionHandler: nil)

    } else {

        // Fallback on earlier versions.

        UIApplication.shared.openURL(settingsUrl)
    }
}

This works perfectly fine on an iOS 9 device, but not on an iOS 10 one. The problem is that whilst the app will send the user to the settings app in iOS 10, it immediately crashes with no crash logs. If I use this same method to open up a website like Google it works perfectly fine on both iOS 9 and 10. I have done a lot of research and it appears they have changed some things with the URL schemes, but can't find any fixes / workarounds.

like image 874
BenSDConway Avatar asked Sep 30 '16 13:09

BenSDConway


1 Answers

I found a way to open settings app in iOS by adding a setting bundle to my project and using this code:

    let settingsUrl = NSURL(string:UIApplicationOpenSettingsURLString) as! URL
    UIApplication.shared.open(settingsUrl, options: [:], completionHandler: nil)

It looks like this is the only way that you can use in order to open native settings application if your application doesn't have a custom keyboard.

like image 187
Joaquín Enrique Gómez López Avatar answered Oct 12 '22 04:10

Joaquín Enrique Gómez López