13

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.

rmaddy
  • 314,917
  • 42
  • 532
  • 579
  • You can't since iOS5.1: http://stackoverflow.com/questions/8246070/ios-launching-settings-restrictions-url-scheme – Larme Oct 30 '15 at 14:21
  • 1
    This is an English-only website. Please translate (Use http://translate.google.com if needed). Or use [Stackoverflow Portuguese](http://pt.stackoverflow.com/). Este é um Inglês-only website. Por favor, traduzir (Use http://translate.google.com se necessário). Ou use [Stackoverflow Português](http://pt.stackoverflow.com/). – rmaddy Oct 30 '15 at 14:21
  • I'm sorry, the translation was sent wrong. – Helton Fernandes Sampaio Oct 30 '15 at 15:16
  • 1
    I tried it on 9.1 and it works – Fernando García Corrochano Nov 11 '15 at 09:33
  • @Fernando Garcia Corrochano. Please could you post your code to see what I did wrong? – Helton Fernandes Sampaio Nov 12 '15 at 11:27
  • This is my code (same as yours) if (&UIApplicationOpenSettingsURLString != NULL) { [[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"prefs:root=WIFI"]]; } Try to add prefs tu URL schemes like http://stackoverflow.com/a/31253743/3668465 did – Fernando García Corrochano Nov 12 '15 at 12:08
  • @FernandoGarcíaCorrochano. -> My God, the code worked !!! Thank you very very very much !! Really to run the code have to add the "prefs" in the URL scheme. My friend please, mount a response with your solution so I can give an + – Helton Fernandes Sampaio Nov 12 '15 at 13:58

8 Answers8

11

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

habakuk
  • 2,712
  • 2
  • 28
  • 47
  • see [this](http://stackoverflow.com/questions/40126813/how-to-programmatically-open-the-wifi-settings-in-objective-c-on-ios-10) post to get the solution – Shuvo Joseph Nov 02 '16 at 05:41
  • 7
    This 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." – Bersaelor Aug 23 '18 at 20:45
  • 3
    We are no more supposed to use this way to open Wi-Fi. Apple rejects the binary. – Karthick Ramesh Oct 04 '18 at 00:38
7

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"]];
    }
}
Shuvo Joseph
  • 894
  • 1
  • 12
  • 21
7

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)
                }
Karthick Ramesh
  • 1,451
  • 20
  • 30
  • How does this help? This code just launches the settings for the app, it has nothing to do with the WiFi settings – Vince Varga May 29 '19 at 19:38
  • Please 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. – Karthick Ramesh May 29 '19 at 20:15
  • Sorry, 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). – Vince Varga May 30 '19 at 10:37
3

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.
    }
Vinod Sutar
  • 101
  • 6
2

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 {
  ...
}
rmaddy
  • 314,917
  • 42
  • 532
  • 579
Bart
  • 47
  • 5
2
//Pre iOS 10
NSURL *url = [NSURL URLWithString:@"prefs:root=WIFI"];
if (![[UIApplication sharedApplication] canOpenURL:url])
{   //iOS 10+
    url = [NSURL URLWithString:@"App-Prefs:root=WIFI"];
}
[[UIApplication sharedApplication] openURL:url];
d_o_o_b
  • 3
  • 2
Pierre
  • 8,397
  • 4
  • 64
  • 80
1

Swift 4.2, iOS 12

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: UIApplication.openSettingsURLString),
            UIApplication.shared.canOpenURL(settingsURL)
            else {
                return false
        }

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

Usage: UIApplication.openAppSetting()

I also used non-public URL scheme, such as: prefs:root=, but my app was rejected. So if you're trying to do more specific stuff with deeplinking, don't waste your time because at the moment you can't!

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

You can use this option:

iOS >= 4.1 it's possible to obtain SSID of wireless network that device is currenctly connected to.

For this you'd use function CNCopyCurrentNetworkInfo

Details on implemenation: iPhone get SSID without private library

Community
  • 1
  • 1
pedro.olimpio
  • 1,478
  • 2
  • 22
  • 43