Call to NEHotspotHelper.register never returns

孤者浪人 提交于 2020-01-02 14:55:22

问题


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.

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.

Below is my code

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!

EDIT: 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.


回答1:


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.

See more: https://forums.developer.apple.com/message/138756#138756



来源:https://stackoverflow.com/questions/41095687/call-to-nehotspothelper-register-never-returns

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!