Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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"]];
like image 668
Shuvo Joseph Avatar asked Oct 19 '16 09:10

Shuvo Joseph


2 Answers

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.

like image 127
Ahmad F Avatar answered Sep 21 '22 13:09

Ahmad F


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;
    }
}
like image 29
Drico Avatar answered Sep 18 '22 13:09

Drico