Reconnection to the wifi the iPad had connected to

I'm developing an app and want to control the Wifi connection in my app using iPad.

The app will reconnect to the wifi that the iPad had connected to.

Also I want to connect to wifi without entering a password.


When we connect to Wifi with iPad's setting app, we do not enter password, which I want to let the app run for.


I received an email from networkextension@apple.com regarding Hotspot Helper Request rejection.

It is written that the Hotspot Helper API is not designed for the use I have identified.

What can I do for solving this problem?

Please let me know if you have an idea or same experiences.

Replies

If you want to connect your device to a known Wi-Fi configuration from an app with a pre-defined passcode you can use NEHotspotConfiguration for this functionality. Specifically, you can define the Wi-Fi configuration your device/app needs and then apply it when it makes sense:


let passphrase = "networkPassphrase"
let  SSID = "networkSSID"

let hotspotConfig = NEHotspotConfiguration(ssid: SSID, passphrase: passphrase, isWEP: false)
hotspotConfig.joinOnce = true // (Optional use for one-time, short-term connections)


NEHotspotConfigurationManager.shared.apply(hotspotConfig) { (error) in
  // Identify successful connection
}

// Remove the Wi-Fi network configuration
NEHotspotConfigurationManager.shared.removeConfiguration(forSSID: SSID)


Matt Eaton

DTS Engineering, CoreOS

meaton3 at apple.com

Thank you, meaton.


I don't know the wifi's password, becouse the wifi is managed by my customer.
Also the wifi is setted up by Configuration Profile.


We don't manually enter a password when connecting to wifi setted up by the configuration profile.


Can I connect the wifi without password by Swift programming in this case?

Ah, I see what you mean about the password now. If you are connecting to a Wi-Fi network that requires a passphrase, then you will need to know the passphrase in your application to provide this functionality. If the network is open and only required a SSID and then you could connect without further authentication.

| I don't know the wifi's password, becouse the wifi is managed by my customer.

| Also the wifi is setted up by Configuration Profile.


For an entire list of these configuration settings, checkout the NEHotspotConfiguration documentation.



Matt Eaton

DTS Engineering, CoreOS

meaton3 at apple.com

meaton, thank you for your response.


I tried a Wifi connection using NEHotspotConfiguration. However, I did not get the results I wanted.

Please give me advice.


I tried the following:

1. I prepared an Wifi (WPA2).

2. I created a Configuration Profile to connect to this Wifi and installed it on my iPad.

3. I have confirmed that the iPad can connect to this Wifi manually without entering a passphrase. Later, I disconnected this Wifi.

4. I made a program to connect to this Wifi only by SSID.

However, I could not connect to the Wifi using this program.


The code at that time.

@objc(connectWifi:) public func connectWifi(_ command: CDVInvokedUrlCommand) {

    if #available(iOS 11.0, *) {
      let configuration = NEHotspotConfiguration.init(ssid: "HW01L-50ABD5")
      NEHotspotConfigurationManager.shared.apply(configuration) { (error) in
        if (error == nil) {
          print("success")
          let result = CDVPluginResult(status: CDVCommandStatus_OK, messageAs: "OK")
          self.commandDelegate.send(result, callbackId: command.callbackId)
        } else {
          print("error")
          let result = CDVPluginResult(status: CDVCommandStatus_ERROR, messageAs: error?.localizedDescription)
          self.commandDelegate.send(result, callbackId: command.callbackId)
        }
      }
    } else {

    }
  }


I experimented with:

5. I made a program to connect to Wifi with SSID and passphrase.

However, the iPad did not connect to Wifi.


6. I have deleted the Configuration Profile from this iPad.

7. I ran the program created in '5'.

iPad connected to this Wifi.


The code at that time.

@objc(connectWifi:) public func connectWifi(_ command: CDVInvokedUrlCommand) {

    if #available(iOS 11.0, *) {
      let configuration = NEHotspotConfiguration.init(ssid: "HW01L-50ABD5", passphrase: "XXXXXXXX", isWEP: false)
      NEHotspotConfigurationManager.shared.apply(configuration) { (error) in
        if (error == nil) {
          print("success")
          let result = CDVPluginResult(status: CDVCommandStatus_OK, messageAs: "OK")
          self.commandDelegate.send(result, callbackId: command.callbackId)
        } else {
          print("error")
          let result = CDVPluginResult(status: CDVCommandStatus_ERROR, messageAs: error?.localizedDescription)
          self.commandDelegate.send(result, callbackId: command.callbackId)
        }
      }
    } else {

    }
  }


I cannot include the passphrase in programs I make.

What API can I use to connect to Wifi defined in the configuration profile?

Interesting. If you have a test device, I would test this scenario with iOS 13.4 Beta also as there was bug fixes for this type of scenario added to 13.4. As to diagnosing what is happening, you can take a sysdianose while you are reproducing the issue with the Wi-Fi debugging profile installed. After you get the sysdiagnose the WiFiManager log might provide more information on what is happening during the time of join.


I also think that this should be captured in a bug report. Please open one here and follow up on this thread with the bug number.



Matt Eaton

DTS Engineering, CoreOS

meaton3 at apple.com