5

My question is about private API in IOS. Is there some API to manage WiFi connection? For example I'm using Apple80211.framework to scan WiFi networks but it's unusable for connecting.

My app isn't for appstore.

Colin D
  • 5,641
  • 1
  • 23
  • 35
Nathan
  • 53
  • 1
  • 1
  • 5

4 Answers4

7

We can programmatically connect wifi networks after iOS 11 public API. You can connect wifi using SSID and password like following.

Swift

var configuration = NEHotspotConfiguration.init(ssid: "wifi name", passphrase: "wifi password", isWEP: false)
configuration.joinOnce = true

NEHotspotConfigurationManager.shared.apply(configuration) { (error) in
    if error != nil {
        //an error occurred
        print(error?.localizedDescription)
    }
    else {
        //success
    }
}

Don't forget import NetworkExtension.

Savas Adar
  • 4,083
  • 3
  • 46
  • 54
3

I ran into this issue last year and after quite a bit of digging I came across a helpful example called SOLStumbler. For this app to work your device must be jailbroken. I modified SOLStumbler and threw up a sample app on github. It uses the IPConfiguration bundle to access Apple80211 framework, which allows you to associate to a network. The readme contains the custom build instructions.

https://github.com/devinshively/wifiAssociate

dm shively
  • 107
  • 1
  • 7
2

No need for private API any more! With iOS 11, Apple provided a public API you can use to programmatically join a WiFi network without leaving your app.

The class you’ll need to use is called NEHotspotConfiguration.

To use it, you need to enable the Hotspot capability in your App Capabilities (Adding Capabilities). Quick working example :

NEHotspotConfiguration *configuration = [[NEHotspotConfiguration
 alloc] initWithSSID:@“SSID”];
configuration.joinOnce = YES;

[[NEHotspotConfigurationManager sharedManager] applyConfiguration:configuration completionHandler:nil];

This will prompt the user to join the “SSID” WiFi network. It will stay connected to the WiFi until the user leaves the app.

This doesn't work with the simulator you need to run this code with an actual device to make it work.

More informations here : https://developer.apple.com/documentation/networkextension/nehotspotconfiguration

Enthouan
  • 716
  • 6
  • 7
0

It's possible in any version of iOS which can load a configuration profile: the app needs to generate a profile with the desired network credentials, and host a web server which provides the profile to Mobile Safari.

alfwatt
  • 2,010
  • 2
  • 18
  • 29