调用NEHotspotHelper.register永不返回 [英] Call to NEHotspotHelper.register never returns

查看:285
本文介绍了调用NEHotspotHelper.register永不返回的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个iOS应用,该应用需要自动连接到WiFi网络.我们曾要求苹果公司提供NEHotspotHelper扩展程序,该扩展程序已获得批准.

I am working on an iOS app which has a requirement to automatically connect to a WiFi network. We had requested for a NEHotspotHelper extension from Apple which is approved.

现在,我正在尝试自动连接到周围的WiFi网络.但是对方法 NEHotspotHelper.register 的调用永远不会返回.我已在应用程序的权利文件中添加了权利 com.apple.developer.networking.HotspotHelper ,并且还在使用启用了该权利的新创建的配置文件.试图从上周开始运作.看起来像一件小东西,我发现很难抓到.请帮忙.

Now I am trying to auto connect to the WiFi network around. But the call to method NEHotspotHelper.register never returns. I have added the entitlement com.apple.developer.networking.HotspotHelper in the entitlement file of the app and am also using a newly created provisioning profile with the said entitlement enabled. Trying to get it work from last week. Looks like a small thing which I am finding difficult to catch. Please help.

下面是我的代码

if let strWiFi =  UserDefaults.standard.value(forKey:"WiFiSSID") as? String {
     let queue = DispatchQueue(label: "com.mycompany.myapp")
     NEHotspotHelper.register(options: nil, queue: queue,
     handler: {(_ cmd: NEHotspotHelperCommand) -> Void in
     if cmd.commandType == .evaluate || cmd.commandType == .filterScanList {
     var hotspot:NEHotspotNetwork?
     for network: NEHotspotNetwork in cmd.networkList! {
     print("network name:\(network.ssid)")
     if (network.ssid == strWiFi) {
     network.setConfidence(.high)
     let strPassword = UserDefaults.standard.value(forKey:"WiFiPassword") as? String
     network.setPassword(strPassword!)
     hotspot = network
     }
     }
     let response = cmd.createResponse(.success)

     if(hotspot != nil) {
     response.setNetwork(hotspot!)
     }

     response.deliver()
     }
     })

我们非常感谢您的帮助!

Any help is highly appreciated!

现在,当我尝试断开连接,然后重新连接回WiFi时,注册成功,但仅返回当前连接网络的详细信息.我需要周围所有WiFi网络的详细信息.

Now when I tried to disconnect and then reconnecting back to the WiFi then it registration succeeds but returns only the details of currently connected network. I need the details of all WiFi networks around.

推荐答案

需要输入设置"-> Wi-fi,帮助器仅在输入屏幕后才执行,我也尝试过自动连接,但是用户需要选择第一次连接的网络. 如果用户选择一次连接网络,则下次可能会自动连接,因为可能会在维护"命令中输入.

Is need to enter in Settings -> Wi-fi, the helper only execute if enter in the screen, I tried too make auto connect, but the user need to select the network to connect in the first time. If the user select to connect network once, the next time may auto connect, because may enter in command Maintain.

查看更多: https://forums.developer.apple.com/message/138756#138756

这篇关于调用NEHotspotHelper.register永不返回的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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