I'm trying to handle the error in NEHotspotConfigurationManager connection method.When i try even OS network connect dialog showing with "Cannot connect" response return as "Success".
In my flow i'm trying to connect to a private network. First i connect using below code and then set the IP Address,SubNetMask,Router and DNS server address manually to already added Wifi by running below code. I'm doing this manually because as i understand you cannot set the IP Address,SubNetMask,Router and DNS server address using Swift.
https://forums.developer.apple.com/forums/thread/96834?page=2
I read the above thread and what i can understand from that is it's a bug in the os method. So does this problem fixed on latest iOS version? or is there a way to handle this problem?
Error handler code→
let eapSetting = NEHotspotEAPSettings()
eapSetting.username = self.username
eapSetting.password = self.password
eapSetting.supportedEAPTypes = [NEHotspotEAPSettings.EAPType.EAPPEAP.rawValue as NSNumber]
eapSetting.trustedServerNames = ["ABC"]
NEHotspotConfigurationManager.shared.removeConfiguration(forSSID: self.ssid)
let hotspotConfiguration = NEHotspotConfiguration(ssid: self.ssid, eapSettings: eapSetting)
manager.apply(hotspotConfiguration){ (error) in
if let error = error {
print("Error")
return
} else {
print("Success")
return
}
}
I'm doing this manually because as i understand you cannot set the IP Address, SubNetMask, Router and DNS server address [programmatically].
That’s correct.
What sort of network requires you to set these parameters?
I usually see questions like this from folks building apps for third-party accessories. If that’s the case here, I recommend you read Working with a Wi-Fi Accessory, linked to from Extra-ordinary Networking.
When i try even OS network connect dialog showing with "Cannot connect" response return as "Success".
Right. This is an oddity with the semantics of this API. The completion handler tells you whether NEHotspotConfigurationManager
has accepted the configuration request. After that the Wi-Fi subsystem kicks off the process to join the network. There’s no way to get detailed errors from that process or to suppress the alert displayed to the user.
There isn’t a good way around this. You can monitor the current networking state to see if the join request was successful. However, if the request fails you don’t get notified of that. All you can do is time out after some point.
Share and Enjoy
—
Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"