How to open WIFI setting in Swift 3

RJ168 picture RJ168 · Sep 29, 2016 · Viewed 8.9k times · Source

I want to open WIFI setting section from my iOS application, my code was working well before Swift 3 with iOS 9.2

if let settingsURL = URL(string: AppSettingsWifiUrl) {
    UIApplication.shared.openURL(settingsURL)
}

But after updating it is not working with Xcode 8 + Swift 3 + iOS 10, can anybody help here?

Answer

chawki picture chawki · Feb 15, 2018

We can't do this anymore on iOS 11, we can just open the settings :

if let url = URL(string:UIApplicationOpenSettingsURLString) {
    if UIApplication.shared.canOpenURL(url) {
       let url =  UIApplication.shared.open(url, options: [:], completionHandler: nil)
    }
}