Swift 连接到 SSID 时密码无效
Swift Invalid passphrase when connecting to SSID
我正在尝试使用 NEHotspotConfiguration 以编程方式连接(请参阅下面的代码)。但是,当我尝试连接时,错误显示:"invalid WPA/WPA2 passphrase length",但我连接的是开放网络,不需要密码。
我见过一些解决方案,但出于质量原因,我无法使用许多解决方法。
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.")
}
}
我该怎么做才能解决这个问题?
有一个特定的 API 用于开放网络。查看 API docs for NEHotspotConfiguration 看起来您应该使用 init(ssid: String)
而不是 init(ssid: String, passphrase: String, isWEP: Bool)
我正在尝试使用 NEHotspotConfiguration 以编程方式连接(请参阅下面的代码)。但是,当我尝试连接时,错误显示:"invalid WPA/WPA2 passphrase length",但我连接的是开放网络,不需要密码。
我见过一些解决方案,但出于质量原因,我无法使用许多解决方法。
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.")
}
}
我该怎么做才能解决这个问题?
有一个特定的 API 用于开放网络。查看 API docs for NEHotspotConfiguration 看起来您应该使用 init(ssid: String)
而不是 init(ssid: String, passphrase: String, isWEP: Bool)