I’m encountering an unexpected issue while using NEHotspotConfigurationManager.shared.apply(...) to connect to a Wi-Fi network. Specifically, I’m receiving a userDenied error, even though the user did not interact with any system prompt.
Here’s a version of the code I’m using:
let config = NEHotspotConfiguration(ssid: ssid, passphrase: passphrase, isWEP: false)
// config.joinOnce = true
NEHotspotConfigurationManager.shared.apply(config) { error in
if let err = error {
let nsErr = err as NSError
mlog("err.code:\(nsErr.code)")
if nsErr.code == NEHotspotConfigurationError.alreadyAssociated.rawValue {
self.findWiFiListAndConnect(ssid, passphrase, overtimeSec, timeStart)
} else {
self.cmdDelegateQueue.async {
self.delegate?.wifiClose(nsErr.code)
}
}
}
}
The error returned is:
wifiClose status: 7
Which corresponds to NEHotspotConfigurationError.userDenied. According to the official Apple documentation, this error should only occur when the user explicitly cancels the system dialog. However, in my case:
• No system dialog appears.
• The user does nothing, yet the error is still returned.
• This issue does not happen every time, but it has been observed across multiple devices.
Additional info:
• iOS version: 18.5
• Device model: iPhone
• joinOnce is not set (defaults to false)
• Existing configuration is removed using removeConfiguration(...) before applying
Is it possible that under certain system states (e.g. backgrounded, network restrictions, or app permissions), iOS silently fails without showing the prompt?
Has anyone else encountered this issue, or does anyone know what could cause this behavior?
Any help is greatly appreciated!