Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Connect to WiFi programmatically in ios

Tags:

wifi

ios5

api

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.

like image 238
Nathan Avatar asked Dec 20 '22 08:12

Nathan


2 Answers

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.

like image 182
Savas Adar Avatar answered Feb 06 '23 07:02

Savas Adar


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

like image 26
dm shively Avatar answered Feb 06 '23 07:02

dm shively