首页 文章

NEHotspotConfigurationManager对于无效密码/ SSID没有错误

提问于
浏览
3

当我使用 NEHotspotConfigurationManager 连接到WiFi接入点,并且我故意使用无效密码或SSID时,我没有得到我期望的程序化反馈 . 用户通过警报收到连接失败的反馈,但在提供给 apply 函数的完成块中, error 为nil,与成功案例相同 . 这使我无法区分成功和失败案例 . NEHotspotConfigurationError 同时包含 .invalidSSID.invalidWPAPassphrase . 我希望这些会被退回 . 这对我来说就像一个雷达,但我想先得到一些反馈 .

NEHotspotConfigurationManager.shared.removeConfiguration(forSSID: "test")
let configuration = NEHotspotConfiguration(ssid: "test", passphrase: "testasdasd", isWEP: false)
configuration.joinOnce = true
NEHotspotConfigurationManager.shared.apply(configuration) { (error) in
    // error is nil
}

2 回答

  • 7

    在向Apple提交雷达后,看起来这个API正在按设计运行 . 成功/失败情况仅适用于热点配置的应用 .

    好消息是,我已经找到了一个合适的工作方法,使用 CNCopySupportedInterfaces 验证应用程序是否确实连接到它所说的SSID .

    let ssid = "test"
    NEHotspotConfigurationManager.shared.removeConfiguration(forSSID: said)
    let configuration = NEHotspotConfiguration(ssid: ssid, passphrase: "testasdasd", isWEP: false)
    configuration.joinOnce = true
    NEHotspotConfigurationManager.shared.apply(configuration) { (error) in
        if let error = error as NSError? {
                // failure
            } else {
                if self.currentSSIDs().first == ssid {
                    // Real success
                } else {
                    // Failure
                }
            }
    }
    

    使用以下定义的此功能:

    func currentSSIDs() -> [String] {
        guard let interfaceNames = CNCopySupportedInterfaces() as? [String] else {
            return []
        }
        return interfaceNames.flatMap { name in
            guard let info = CNCopyCurrentNetworkInfo(name as CFString) as? [String:AnyObject] else {
                return nil
            }
            guard let ssid = info[kCNNetworkInfoKeySSID as String] as? String else {
                return nil
            }
            return ssid
        }
    }
    
  • 0

    使用密码错误的无效登录仍然是此API的问题 . 如果您已经连接到ssid,那么您将始终与呼叫中的好密码或错误密码“已经关联” . 上述逻辑工作的唯一方法是,如果您从现有的ssid更改为另一个有效的现有ssid并将其传递给错误的密码,则上述逻辑将捕获错误的密码 . 对给定的ssid使用removeConfiguration似乎没有任何效果 .

相关问题