how to programmatically open the WIFI settings in objective c in iOS9
Solution 1
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
Solution 2
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"]];
}
}
Solution 3
As per Apple's New Review standards, we are not supposed to use this way to open Wi-Fi Settings. I have been using this for long time in my app and recently Apple rejected with the below comment.
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.
So you can just navigate to settings of the app by using UIApplicationOpenSettingsURLString.
Swift Code:
if let settingsUrl = URL.init(string: UIApplicationOpenSettingsURLString), UIApplication.shared.canOpenURL(settingsUrl) {
UIApplication.shared.openURL(settingsUrl)
}
Solution 4
All conditions:
NSURL * urlCheck1 = [NSURL URLWithString:@"App-Prefs:root=WIFI"];
NSURL * urlCheck2 = [NSURL URLWithString:@"prefs:root=WIFI"];
NSURL * urlCheck3 = [NSURL URLWithString:UIApplicationOpenSettingsURLString];
if ([[UIApplication sharedApplication] canOpenURL:urlCheck1])
{
[[UIApplication sharedApplication] openURL:urlCheck1];
}
else if ([[UIApplication sharedApplication] canOpenURL:urlCheck2])
{
[[UIApplication sharedApplication] openURL:urlCheck2];
}
else if ([[UIApplication sharedApplication] canOpenURL:urlCheck3])
{
[[UIApplication sharedApplication] openURL:urlCheck3];
}
else
{
//Unable to open settings app.
}
Solution 5
You can't get straight to wifi setting with openURL. All you can do is to open settings for your own app.
if (&UIApplicationOpenSettingsURLString != nil) {
NSURL *URL = [NSURL URLWithString:UIApplicationOpenSettingsURLString];
[[UIApplication sharedApplication] openURL:URL];
} else {
...
}
Helton Fernandes Sampaio
Updated on July 09, 2022Comments
-
Helton Fernandes Sampaio almost 2 years
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.
-
Helton Fernandes Sampaio over 8 yearsIts solution opens the application settings menu. What I'm wondering is how to open the WiFi settings menu.
-
rmaddy over 8 yearsHow does this explain how to open the WiFi settings page in the Settings app on iOS?
-
Helton Fernandes Sampaio over 8 yearsYes Yes. However, I have an application installed on my iPhone that does exactly what I'm looking for, his name is the "Launcher", you know? If this application can do, because we can not do the same?
-
shim over 7 yearsBroken in iOS 10. Any fixes?
-
BigCheesy over 7 yearsYes, this is broken in iOS10
-
Shuvo Joseph over 7 yearssee this post to get the solution
-
Shuvo Joseph about 7 yearsThis works fine on iOS 10
-
Bersaelor over 5 yearsThis is forbidden by the app store guidelines, I just had an app rejected by the review team for doing this: "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."
-
Karthick Ramesh over 5 yearsWe are no more supposed to use this way to open Wi-Fi. Apple rejects the binary.
-
Karthick Ramesh over 5 yearsWe are no more supposed to use this way to open Wi-Fi. Apple rejects the binary.
-
Karthick Ramesh over 5 yearsWe are no more supposed to use this way to open Wi-Fi. Apple rejects the binary.
-
Karthick Ramesh over 5 yearsWe are no more supposed to use this way to open Wi-Fi. Apple rejects the binary.
-
Pierre over 5 years@KarthickRamesh noted. Thanks
-
Vince Varga almost 5 yearsHow does this help? This code just launches the settings for the app, it has nothing to do with the WiFi settings
-
Karthick Ramesh almost 5 yearsPlease read the answer properly! Apple no more suggests to navigate to the wifi settings page directly. It just restricts the user to go yo settings. Apple expects the user himself to navigate to corresponding settings page.
-
Vince Varga almost 5 yearsSorry, what I meant to ask is "how does this code snippet help". Your answer is correct and helpful, but the code snippet doesn't really help with jumping to the WiFi settings (because it's not possible at all anymore, I got that).