Search code examples
iosobjective-ciphonewifiios10

How to programmatically open the WIFI settings in Objective-C on iOS 10


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"]];

Solution

  • 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"]];
        }
    }