NEHotspotConfigurationManager getting this alert:"Unable to join the network<name of network>" while error is nil

I think this behavior is a iOS bug and we cannot avoid.

This problem was also discussed in Apple Developer Forum and answer of Apple staff was below

"I’ve got nothing to say here beyond what I said on 13 Feb. The fact that errors from the Wi-Fi subsystem don’t get reported via the completion handler is expected behaviour. If you don’t like that behavior — and, to be clear, I personally agree with you about that — the best way forward is to file a bug report requesting that it be changed. Please post your bug number, just for the record."

This was discussed here

So I do not have great ideas, unfortunately. All ideas I have are two below (these do not solve this problem perfectly.)

  1. Wait for a bug fix in the future release.
  2. Separate "Applying Configuration" code & Communication code like below.
@IBAction func setConfigurationButtonTapped(_ sender : Any) {
    manager.apply(hotspotConfiguration) { (error) in
    if(error != nil){
        // Do error handling
    }else{
        // Wait a few seconds for the case of showing "Unable to join the..." dialog.
        // Check reachability to the device because "error == nil" does not means success.
    }
}
@IBAction func sendButtonTapped(_ sender : Any) {
    self.startSession()
}

iOS 13 - Patch

I had the same problem, but I solved it by deleting first all the existing configuration entries:

NEHotspotConfigurationManager.shared.getConfiguredSSIDs { (wifiList) in
    wifiList.forEach { NEHotspotConfigurationManager.shared.removeConfiguration(forSSID: $0) }
    // ... from here you can use your usual approach to autoconnect to your network
}

Maybe it's not always a possible solution since it's a bit drastic, but for me worked like a charm.

PS: I use this in an app that runs iOS 13. As far as I know should work also on iOS 11 and 12, but I didn't test it.