Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to programmatically open the WIFI settings in objective c in iOS9

I'm trying to access the WIFI settings through my application using Objective-C. But can not find any way. Could someone help me?

Already tested with:

[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"prefs:root=WIFI"]];

Does not work on iOS 9.

like image 847
Helton Fernandes Sampaio Avatar asked Oct 30 '15 14:10

Helton Fernandes Sampaio


2 Answers

This works fine on iOS 10,

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

In the URL Schemes write

prefs

Then Call,

- (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"]];
    }
}
like image 97
Shuvo Joseph Avatar answered Oct 19 '22 21:10

Shuvo Joseph


This is my code

if (&UIApplicationOpenSettingsURLString != NULL) { 
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"prefs:root=WIFI"]]; 
} 

Try to add prefs to URL schemes like https://stackoverflow.com/a/31253743/3668465 did

like image 11
Fernando García Corrochano Avatar answered Oct 19 '22 20:10

Fernando García Corrochano