5

I'm creating an app on Swift, and I need to know, if there's any way I can programatically auto connect an iPhone to a WiFi giving as paremeters the SSID and the Password from that WiFi Network.

Thanks in advance.

Schavcovsky
  • 81
  • 1
  • 2
  • 9

3 Answers3

5

Below code will work on Xcode 9 and iOS 11

let WiFiConfig = NEHotspotConfiguration(ssid: "Mayur1",
                                                  passphrase: "123456789",
                                                  isWEP: false)

    WiFiConfig.joinOnce = false
    NEHotspotConfigurationManager.shared.apply(WiFiConfig) { error in
        // Handle error or success
        print(error?.localizedDescription)
Mayur Rathod
  • 361
  • 3
  • 13
1

Quotation from Apple Developer Documentation:

The NEHotspotHelper interface allows an app to participate in the process of joining Wi-Fi/hotspot networks. Such an app is referred to as a Hotspot Helper. A Hotspot Helper receives commands to be processed in the background that allow it to participate in the Hotspot Network state machine.

wzso
  • 3,482
  • 5
  • 27
  • 48
0

Not possible unfortunately! Too many issues that Apple would be not okay with. If you're working with a jailbroken device it may be possible (if it's not going on the app store, either)

Here's a question similar to yours you might want to look at

Community
  • 1
  • 1
brimstone
  • 3,370
  • 3
  • 28
  • 49
  • Devicescape has done it. So I don't think it is correct to say that Apple would not be OK with it. The question of how? Please let me know when you figure it out. – pjc Feb 25 '16 at 18:25
  • @pjc All evidence shows that this capability isn't available. Apple removed the ability for private frameworks to be used, therefore there is no way (Devicescape must have used one of these) For jailbroken devices: https://github.com/devinshively/wifiAssociate See another question: http://stackoverflow.com/questions/2341657/how-to-detect-and-connect-to-a-wifi-network-programmatically-using-apple-sdk – brimstone Feb 25 '16 at 20:37
  • I've been digging in a little bit. I think they used this public library. Probably, so yeah, not possible. Voted up. https://developer.apple.com/library/prerelease/ios/documentation/NetworkExtension/Reference/NEHotspotHelperClassRef/index.html but – pjc Feb 27 '16 at 05:12