Search code examples
iosswiftnetworkextension

NEHotspotConfigurationErrorDomain Code=5 "invalid EAP settings."


I'm using NEHotspotConfigurationManager with on iOS 11 iPhone to connect to specific Wi-Fi spot and then disconnect from it.

Here is the code:

let domainName = ""
let hotspotSettings = NEHotspotHS20Settings.init(domainName: domainName, roamingEnabled: true)
let hotspotEAPSettings = NEHotspotEAPSettings()
hotspotEAPSettings.username = *****
hotspotEAPSettings.password = ******
hotspotEAPSettings.isTLSClientCertificateRequired = true
hotspotEAPSettings.supportedEAPTypes = [21]
hotspotEAPSettings.trustedServerNames = [""]
hotspotEAPSettings.ttlsInnerAuthenticationType = .eapttlsInnerAuthenticationMSCHAPv2
print(hotspotEAPSettings)
let hotspotConfig = NEHotspotConfiguration.init(hs20Settings: hotspotSettings, eapSettings: hotspotEAPSettings)
print( hotspotConfig.ssid)
NEHotspotConfigurationManager.shared.apply(hotspotConfig) {[unowned self] (error) in
    print(error?.localizedDescription as Any)// gives Error Domain=NEHotspotConfigurationErrorDomain Code=5 "invalid EAP settings." 
    print(error as Any)
    if let error = error {
        self.showError(error: error)
    } else {
        self.showSuccess()
    }
}

Question is: what happened? Why it prompts me error "invalid EAP settings", and also what does this error mean?


Solution

  • For this first we had to save certificate which comes in .mobileconfig file into iPhone keychain in $TeamID.com.apple.networkextensionsharing group, also enable the keychain access group in xCode capability and add $TeamID.com.apple.networkextensionsharing into entitlements.After successfully save the certificate into keychain it works.