NEHotspotConfigurationManager收到此警报:“无法加入网络<网络名称>".虽然错误为零 [英] NEHotspotConfigurationManager getting this alert:"Unable to join the network<name of network>" while error is nil

查看:1113
本文介绍了NEHotspotConfigurationManager收到此警报:“无法加入网络<网络名称>".虽然错误为零的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

因此,我正在尝试通过闭合器监视连接状态:

So i am trying to monitor the connection status by closers :

 func reconnect(success: @escaping () -> Void, failure: @escaping () -> Void) {
    let manager = NEHotspotConfigurationManager.shared
    let ssid = CameraManager.camera.uuid
    let password = "password"
    let isWEP = false
    let hotspotConfiguration = NEHotspotConfiguration(ssid: ssid, passphrase: password, isWEP: isWEP)
    hotspotConfiguration.joinOnce = true
    manager.apply(hotspotConfiguration) { (error) in
        if (error != nil) {

          if let error = error {
                switch error._code {
                case 8:
                    print("internal error")
                    failure()
                case 7:
                    NotificationCenter.default.post(name: Notification.Name(rawValue: "cancelFromHotSpot"), object: nil)
                    failure()
                    self.stopSession()
                case 13:
                    success()
                    DispatchQueue.main.asyncAfter(deadline: .now() + 1.0) {
                        self.startSession()
                    }
                default:
                    break
                }
        }

        if error == nil {
            print("success connecting wifi")
            success()
            DispatchQueue.main.asyncAfter(deadline: .now() + 1.0) {
                self.startSession()
            }
        }
    }
}

但是,在某些情况下,我得到此警报无法加入网络",而错误为零,有什么主意吗?

Yet there is a scenario that i am getting this alert "Unable to join the network" while error is nil, any ideas?

推荐答案

我认为此行为是iOS的错误,我们无法避免.

I think this behavior is a iOS bug and we cannot avoid.

在苹果开发者论坛上也讨论了这个问题,下面是苹果员工的回答

This problem was also discussed in Apple Developer Forum and answer of Apple staff was below

除了2月13日我所说的之外,我无话可说.这是Wi-Fi子系统的错误不会通过完成处理程序报告的事实,这是预期的行为.如果您不喜欢那样的话行为-明确地说,我个人对此表示同意-最好的解决方法是提交一个错误报告,要求对其进行更改.请张贴您的错误号,以供记录."

"I’ve got nothing to say here beyond what I said on 13 Feb. The fact that errors from the Wi-Fi subsystem don’t get reported via the completion handler is expected behaviour. If you don’t like that behavior — and, to be clear, I personally agree with you about that — the best way forward is to file a bug report requesting that it be changed. Please post your bug number, just for the record."

在此处进行了讨论

不幸的是,我没有很好的主意.我的所有想法都在下面两个(这些不能完美地解决这个问题.)

So I do not have great ideas, unfortunately. All ideas I have are two below (these do not solve this problem perfectly.)

  1. 等待将来版本中的错误修复.
  2. 单独的应用配置"代码和通讯代码如下.

@IBAction func setConfigurationButtonTapped(_ sender : Any) {
    manager.apply(hotspotConfiguration) { (error) in
    if(error != nil){
        // Do error handling
    }else{
        // Wait a few seconds for the case of showing "Unable to join the..." dialog.
        // Check reachability to the device because "error == nil" does not means success.
    }
}

@IBAction func sendButtonTapped(_ sender : Any) {
    self.startSession()
}

这篇关于NEHotspotConfigurationManager收到此警报:“无法加入网络<网络名称>".虽然错误为零的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆