所以我试图通过关闭器监视连接状态:
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()
}
}
}
}
然而,有一种情况是,我收到此警报“无法加入网络”,而错误为零,有什么想法吗?
我认为这种行为是 iOS 的一个 bug,我们无法避免。
苹果开发者论坛也讨论了这个问题,苹果工作人员的回答如下
“除了 2 月 13 日所说的之外,我没有什么可说的。Wi-Fi 子系统的错误不会通过完成处理程序报告这一事实是预期的行为。如果您不喜欢这种行为 - 并且,需要明确的是,我个人同意你的观点——最好的方法是提交错误报告,要求进行更改。请发布你的错误编号,仅供记录。”
这已经讨论过here https://forums.developer.apple.com/thread/96834
所以不幸的是我没有什么好主意。我的所有想法如下两个(这些并不能完美解决这个问题。)
- 等待未来版本中的错误修复。
- 单独的“应用配置”代码和通信代码如下。
@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()
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)