8

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?

Eric Aya
  • 69,473
  • 35
  • 181
  • 253
RJ168
  • 1,006
  • 2
  • 12
  • 22
  • http://stackoverflow.com/questions/28152526/how-do-i-open-phone-settings-when-a-button-is-clicked-ios – Sina KH Sep 29 '16 at 08:00
  • @SinaKH: Thank you for your reply, but it will open application setting I want to open WIFI setting. – RJ168 Sep 29 '16 at 08:49

7 Answers7

6

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)
    }
}
chawki
  • 867
  • 1
  • 8
  • 13
4

Edited 26-02-20, Pay attention, in versions later than ios 10 your binary will be rejected

It's possible on iOS 10 and Swift 3

let url = URL(string: "App-Prefs:root=WIFI") //for WIFI setting app
let app = UIApplication.shared
app.openURL(url!)
Lito
  • 2,309
  • 1
  • 23
  • 29
  • Where did you get this information from? Could you please provide a source? – winklerrr Sep 27 '17 at 13:06
  • @winklerrr I found this info on this wiki of ios dev http://iphonedevwiki.net/index.php/Preferences.app and more info https://medium.com/@thanhvtrn/how-to-open-settings-wifi-in-swift-on-ios-10-1d94cf2c2e60 – Lito Sep 27 '17 at 15:20
  • 6
    recently gave an app into review and "App-Prefs:root=Wifi" was a reason for apple to block the release. Here a part of the Mail: Your app uses the "prefs:root=" non-public URL scheme, which is a private entity. The use of non-public APIs is not permitted on the App Store because it can lead to a poor user experience should these APIs change. – Marcel T May 02 '18 at 05:45
  • @MarcelT According to a comment from the second [source](https://medium.com/@thanhvtrn/how-to-open-settings-wifi-in-swift-on-ios-10-1d94cf2c2e60) Lito provided (you have to scroll down to the comment section), Apple shouldn't reject the app?! – winklerrr Aug 19 '18 at 17:04
  • According to this [forum post](https://forums.developer.apple.com/message/186656#186656) from Apples' eskimo, `prefs:root=` or `App-Prefs:root=` is considered as private API and therefore its usage is forbidden and leads to rejection of apps. – winklerrr Aug 19 '18 at 17:12
  • My binary was rejected for review on the app store because of use of prefs:root – Zღk Nov 06 '19 at 13:07
3
 let url=URL(string: "App-Prefs:root=Privacy&path=LOCATION")
        if UIApplication.shared.canOpenURL(url!)
        {
            UIApplication.shared.open(url!, options: [:], completionHandler: {sucess in
            
            })
            
        }
        else{
            UIApplication.shared.open(url!, options: [:], completionHandler: {sucess in
                
            })
        }
3

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

winklerrr
  • 13,026
  • 8
  • 71
  • 88
  • Yes, my app was rejected too because of Themis workaround. The explanation is pretty clear, even Apple won’t guarantee that it will work in the future. IMHO a application shouldn’t have Access to the WiFi settings. It should only be allowed to change settings for the use of the application, which is also possible, for WiFi use, in the settings tab of your application. – Marcel T Aug 19 '18 at 18:53
0

This thing will work with iOS 10 also but you have to add URL types in ur project setting info. URL schemes should be prefs If you need I will share the screen shot so that you can easily achieve.

Thanks

Sandeepk2r
  • 178
  • 8
-1

Just use:

UIApplication.shared.openURL(URL(string:"prefs:root=WIFI")!)
Sina KH
  • 563
  • 4
  • 16
  • 1
    This "bug" will only work on `iOS 9` and was fixed as of `iOS 10`. The usage of this bug leads to rejection of your app. Source: this [forum post](https://forums.developer.apple.com/message/186656#186656) from Apples' eskimo. – winklerrr Aug 19 '18 at 17:16
  • 3
    Apple will reject your app if you use "prefs:root=" – Nitesh Nov 13 '18 at 10:30
-1

Use the following for iOS 10 and above:

if let url = URL(string:"App-Prefs:root=Settings&path=General") { 
    UIApplication.shared.openURL(url)
}
Eric Aya
  • 69,473
  • 35
  • 181
  • 253
SSF
  • 7
  • 2
  • By the way: `App-Prefs:` and `prefs:` URL schemes are considered private API. It's usage was only possible as a "bug" on `iOS9`. Just use `UIApplicationOpenSettingsURLString` as URL string. Source: this [forum post](https://forums.developer.apple.com/message/186656#186656) from Apples' eskimo. – winklerrr Aug 19 '18 at 17:19
  • 2
    Apple will reject the app too using Private API. – Anand Gautam Sep 28 '18 at 06:52