如何在 Swift 3 中打开 WIFI 设置

RJ1*_*168 5 openurl swift3 ios10

我想从我的 iOS 应用程序打开 WIFI 设置部分,我的代码在 Swift 3 和 iOS 9.2 之前运行良好

if let settingsURL = URL(string: AppSettingsWifiUrl) {
    UIApplication.shared.openURL(settingsURL)
}
Run Code Online (Sandbox Code Playgroud)

但是更新后它不适用于 Xcode 8 + Swift 3 + iOS 10,有人可以帮忙吗?

cha*_*wki 5

我们不能在 iOS 11 上再这样做了,我们可以打开设置:

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


Sin*_* KH -1

只需使用:

UIApplication.shared.openURL(URL(string:"prefs:root=WIFI")!)
Run Code Online (Sandbox Code Playgroud)

  • 如果您使用“prefs:root=”,Apple 将拒绝您的应用 (3认同)