NEHotspotConfigurationManager issue

Hi,


I have noticed an issue with the NEHotspotConfigurationManager.


I tested using iphone 8 plus.


using the following code

let configuration = NEHotspotConfiguration.init(ssid: "SSIDname", passphrase: "Password", isWEP: false)
configuration.joinOnce = true

NEHotspotConfigurationManager.shared.apply(configuration) { (error) in
  if error != nil {
  if error?.localizedDescription == "already associated."
  {
  print("Connected")
  }
  else{
  print("No Connected")
  }
  }
  else {
  print("Connected")
  }
}



it returns "Not Connected", but if you observer the phones screen you see that the wifi does in fact connect to the network a second or two after.


could someone let me now if they also see this? I made sure to "forget" the network details before running this.


Thank you

Accepted Reply

To understand what’s going on here you need to understand a little bit about how this API works.

NEHotspotConfigurationManager
is a high-level API for managing configurations but the actual work to join the Wi-Fi network is done by the system’s underlying Wi-Fi infrastructure.
NEHotspotConfigurationManager
calls its completion handler as soon as it has dealt with the request, that is, as soon as it has checked the request and passed it on to that Wi-Fi infrastructure. This has a significant impact on users of
NEHotspotConfigurationManager
:
  • You can’t be guaranteed that the device has actually joined the Wi-Fi network by the time your completion handler is called. In fact this won’t be the case most of the time.

  • If there’s an error joining the Wi-Fi network, that error is reported to the user, not via your completion handler.

If these behaviours cause problems for you in practice — and I can totally see how they might — you should feel free to file a bug report (or enhancement request, depending on your perspective :-) against

NEHotspotConfigurationManager
describing the problem and the behaviour you’d like to see.

Please post your bug number, just for the record.

Finally, even once the device has joined the Wi-Fi network, it can still take time for it to get an IP address, meaning you won’t necessarily be able to communicate over the Wi-Fi network for a while. In your other thread I suggested that you use Bonjour to find your accessory, and this is one of the reasons why. Once the device has joined the accessory’s Wi-Fi network and got an IP address, Bonjour will automatically find your accessory’s service. If you don’t use Bonjour then you have to deal with all of that complexity yourself.

Share and Enjoy

Quinn “The Eskimo!”
Apple Developer Relations, Developer Technical Support, Core OS/Hardware

let myEmail = "eskimo" + "1" + "@apple.com"

Replies

The code is executing faster than the connection is being completed.


Insert a timer/delay/looped (re)check, say 3 sec. duration, before the first print, then run the app again.

To understand what’s going on here you need to understand a little bit about how this API works.

NEHotspotConfigurationManager
is a high-level API for managing configurations but the actual work to join the Wi-Fi network is done by the system’s underlying Wi-Fi infrastructure.
NEHotspotConfigurationManager
calls its completion handler as soon as it has dealt with the request, that is, as soon as it has checked the request and passed it on to that Wi-Fi infrastructure. This has a significant impact on users of
NEHotspotConfigurationManager
:
  • You can’t be guaranteed that the device has actually joined the Wi-Fi network by the time your completion handler is called. In fact this won’t be the case most of the time.

  • If there’s an error joining the Wi-Fi network, that error is reported to the user, not via your completion handler.

If these behaviours cause problems for you in practice — and I can totally see how they might — you should feel free to file a bug report (or enhancement request, depending on your perspective :-) against

NEHotspotConfigurationManager
describing the problem and the behaviour you’d like to see.

Please post your bug number, just for the record.

Finally, even once the device has joined the Wi-Fi network, it can still take time for it to get an IP address, meaning you won’t necessarily be able to communicate over the Wi-Fi network for a while. In your other thread I suggested that you use Bonjour to find your accessory, and this is one of the reasons why. Once the device has joined the accessory’s Wi-Fi network and got an IP address, Bonjour will automatically find your accessory’s service. If you don’t use Bonjour then you have to deal with all of that complexity yourself.

Share and Enjoy

Quinn “The Eskimo!”
Apple Developer Relations, Developer Technical Support, Core OS/Hardware

let myEmail = "eskimo" + "1" + "@apple.com"

Hi Eskimo,


thank you for your response. I opened a case:

https://bugreport.apple.com/web/?problemID=46416108


Ill have to look into a programatic workaround for now. Hopefully ill get something.

It would be nice to see if there will be a change in the near future.


I respect your suggested improvement (bonjour service). It is something I will be reseaching for the next iteration.


Kind Regards