iro*_*oei 6 ios swift networkextension hotspot nehotspothelper
所以我试图通过更紧密的监视连接状态:
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()
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
但是有一种情况是,我收到此错误消息“无法加入网络”,而错误为零,有什么主意吗?
小智 7
我认为这种行为是 iOS 错误,我们无法避免。
这个问题也在 Apple Developer Forum 中讨论过,Apple 工作人员的回答如下
“除了我在 2 月 13 日所说的之外,我在这里没有什么可说的。Wi-Fi 子系统的错误不会通过完成处理程序报告的事实是预期行为。如果你不喜欢这种行为 - 并且,明确地说,我个人同意你的观点——最好的方法是提交一个错误报告,要求对其进行更改。请发布你的错误编号,仅供记录。”
不幸的是,我没有很好的想法。我的所有想法都在下面两个(这些都不能完美地解决这个问题。)
@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.
}
}
Run Code Online (Sandbox Code Playgroud)
@IBAction func sendButtonTapped(_ sender : Any) {
self.startSession()
}
Run Code Online (Sandbox Code Playgroud)