How to open WIFI setting in Swift 3

后端 未结 7 1745
离开以前
离开以前 2021-01-14 00:37

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: AppSetting         


        
7条回答
  •  时光取名叫无心
    2021-01-14 01:09

    iOS 9+

    You can't directly open the Wi-Fi settings tab from your app. You are just allowed to open the settings app in general.

    The following code works with Swift 4 + iOS 9+:

    func openWifiSettings() {
        print("Opening Wi-Fi settings.")
    
        let shared = UIApplication.shared
        let url = URL(string: UIApplicationOpenSettingsURLString)!
    
        if #available(iOS 10.0, *) {
            shared.open(url)
        } else {
            shared.openURL(url)
        }
    }
    

    Source: Apple developer documentation open and openURL


    It was actually possible in iOS 9 to open the Wi-Fi settings tab directly (using private API URL schemes) but this was considered as bug usage.

    Therefore: Don't use App-Prefs:root or pref:root URL schemes as they will lead to rejection of your app by Apple's review check.

    Source: Apple developer forum post from Apple's eskimo.


    iOS 11+

    If you need to connect to a certain Wi-Fi network NEHotspotConfigurationManager maybe helps.

    Source: Apple technical Q&A QA1942

提交回复
热议问题