Swift连接到SSID时无效的密码

时间:2017-12-20 19:15:32

标签: ios swift swift3

我正在尝试使用NEHotspotConfiguration以编程方式连接(请参阅下面的代码)。但是,当我尝试连接时,错误说:“无效的WPA / WPA2密码长度”,但我正在连接一个没有密码的开放网络。

我已经看到了一些解决方案,但由于质量目的,我有很多不能使用的解决方法。

let wifiConfig = NEHotspotConfiguration(ssid: SSID, passphrase: "", isWEP: false)

    wifiConfig.joinOnce = false

    NEHotspotConfigurationManager.shared.apply(wifiConfig) { error in

        if let error = error{
            print("Error: " + (error.localizedDescription))
        }else {
            print("Connected.")
        }
    }

我该怎么做才能解决这个问题?

1 个答案:

答案 0 :(得分:1)

开放网络有一个特定的API。查看API docs for NEHotspotConfiguration,您应该使用init(ssid: String)代替init(ssid: String, passphrase: String, isWEP: Bool)