8

The following code works fine on iOS 9, see this post. But it doesn't work on iOS 10. How to open WIFI settings programmatically on iOS 10

[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"prefs:root=WIFI"]];
Community
  • 1
  • 1
Shuvo Joseph
  • 894
  • 1
  • 12
  • 21

7 Answers7

12

The same exact code should work, but for iOS 10 you need to do some additional work by adding "prefs" to the URL Types:

After selecting your target:

  • Navigate to "Info" tab.
  • After scrolling to bottom, you should see "URL Types" section.
  • Add a new one (by clicking on the plus button) and fill the "URL Schemes" with "prefs".

It should be similar to this:

enter image description here

Now, your code should works fine.

UPDATE:

If it -somehow- did not work as expected, you might want to follow this workaround.

Hope that helped.

Community
  • 1
  • 1
Ahmad F
  • 30,560
  • 17
  • 97
  • 143
8

In iOS 10, a new url is required. Try using this code which tests both urls :

NSArray* urlStrings = @[@"prefs:root=WIFI", @"App-Prefs:root=WIFI"];
for(NSString* urlString in urlStrings){
    NSURL* url = [NSURL URLWithString:urlString];
    if([[UIApplication sharedApplication] canOpenURL:url]){
        [[UIApplication sharedApplication] openURL:url];
        break;
    }
}
Drico
  • 1,284
  • 15
  • 33
3

Try this one :

    if([[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:UIApplicationOpenSettingsURLString]]) {
        [[UIApplication sharedApplication] openURL:[NSURL URLWithString:UIApplicationOpenSettingsURLString]options:[NSDictionary dictionary] completionHandler:^(BOOL success) {
        }];
    }

Thanks :)

3

This works fine on iOS 10,

Go to Targets --> (Application) --> Info --> URL Types --> +

In the URL Schemes write

prefs

See the image, enter image description here

Then add the following code,

-(void)openWifiSettings{
    if ([[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:@"prefs:root=WIFI"]]) {
        [[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"prefs:root=WIFI"]];
    } else {
        [[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"App-Prefs:root=WIFI"]];
    }
}
Shuvo Joseph
  • 894
  • 1
  • 12
  • 21
  • 4
    In iOS 11 `App-Prefs` takes me to the app specific preferences, not the wifi screen. – keegan3d Nov 06 '17 at 00:52
  • 1
    same question here: In iOS11 App-Prefs takes me to the app specific preferences, not the wifi screen. how to solve it in iOS11+ ? – imti May 19 '19 at 09:27
2

Swift 4.2, iOS 12

It's not longer possible to do that kind of deeplinking with the newer version of iOS. My app was recently rejected for using: "non-public URL scheme", such as: prefs:root=. So I'd say to not waste your time with something that we can't currently do, and simply open the settings.

This is the function that I'm currently using in my app for it:

extension UIApplication {

    ...

    @discardableResult
    static func openAppSetting() -> Bool {
        guard
            let settingsURL = URL(string: UIApplicationOpenSettingsURLString),
            UIApplication.shared.canOpenURL(settingsURL)
            else {
                return false
        }

        UIApplication.shared.open(settingsURL)
        return true
    }
}

Usage: UIApplication.openAppSetting()

Alessandro Francucci
  • 1,528
  • 17
  • 25
-1

For Swift:

let url = URL(string: "App-Prefs:root=WIFI")

    if UIApplication.shared.canOpenURL(url!){
        UIApplication.shared.openURL(url!)

    }
Alexander Farber
  • 21,519
  • 75
  • 241
  • 416
krishna
  • 50
  • 5
-2
 let url=URL(string: "App-Prefs:root=WIFI")
// you can change root as your requirements 
        if UIApplication.shared.canOpenURL(url!)
        {
            UIApplication.shared.open(url!, options: [:], completionHandler: {success in

            })

        }
        else{
            UIApplication.shared.open(url!, options: [:], completionHandler: {success in

            })
        }