Nehotspotconfigurationmanager Getting This Alert:"Unable to Join the Network<Name of Network>" While Error Is Nil

NEHotspotConfigurationManager getting this alert:Unable to join the networkname 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()
}

NEHotspotConfigurationManager no error for invalid password/SSID

After filing a radar with Apple, it appears this API is working as designed. The success/failure case only applies to the application of the hotspot configuration.

The good news is, I have found a suitable work around for this in using CNCopySupportedInterfaces to verify if the app has indeed connected to the SSID it said it did.

let ssid = "test"
NEHotspotConfigurationManager.shared.removeConfiguration(forSSID: said)
let configuration = NEHotspotConfiguration(ssid: ssid, passphrase: "testasdasd", isWEP: false)
configuration.joinOnce = true
NEHotspotConfigurationManager.shared.apply(configuration) { (error) in
if let error = error as NSError? {
// failure
} else {
if self.currentSSIDs().first == ssid {
// Real success
} else {
// Failure
}
}
}

Using this function as defined below:

func currentSSIDs() -> [String] {
guard let interfaceNames = CNCopySupportedInterfaces() as? [String] else {
return []
}
return interfaceNames.flatMap { name in
guard let info = CNCopyCurrentNetworkInfo(name as CFString) as? [String:AnyObject] else {
return nil
}
guard let ssid = info[kCNNetworkInfoKeySSID as String] as? String else {
return nil
}
return ssid
}
}

NEHotspotConfigurationErrorDomain Code=8 internal error.

For now, only a restart of the device fixes the issue for some time and then it happens again.

Full log:
Domain=NEHotspotConfigurationErrorDomain Code=8 "internal error." UserInfo={NSLocalizedDescription=internal error.}

I've tried calling NEHotspotConfigurationManager.shared.removeConfiguration(forSSID: ssid) each time before calling:

let hotspot = NEHotspotConfiguration(ssid: ssid, passphrase: pwd, isWEP: false)
hotspot.joinOnce = true
NEHotspotConfigurationManager.shared.apply(hotspot) { (error) in
completionHandler?(error)
}

But the issue still happens...

How to programmatically connect to a WiFi network given the SSID and password

With iOS 11, Apple provided public API you can use to programmatically join a WiFi network without leaving your app.

The class you’ll need to use is called NEHotspotConfiguration.

To use it, you need to enable the Hotspot capability in your App Capabilities (Adding Capabilities). Quick working example :

NEHotspotConfiguration *configuration = [[NEHotspotConfiguration
alloc] initWithSSID:@“SSID-Name”];
configuration.joinOnce = YES;

[[NEHotspotConfigurationManager sharedManager] applyConfiguration:configuration completionHandler:nil];

This will prompt the user to join the “SSID-Name” WiFi network. It will stay connected to the WiFi until the user leaves the app.

This doesn't work with the simulator you need to run this code with an actual device to make it work.

More informations here :
https://developer.apple.com/documentation/networkextension/nehotspotconfiguration



Related Topics



Leave a reply



Submit