NEHotspotHelper.register(options: options, queue: queue) { (cmd: NEHotspotHelperCommand) in
if cmd.commandType == NEHotspotHelperCommandType.filterScanList {
//Get all available hotspots
var list: [NEHotspotNetwork] = cmd.networkList!
//Figure out the hotspot you wish to connect to
// let desiredNetwork : NEHotspotNetwork? = getBestScanResult(list)
var hotspot = [NEHotspotNetwork]()
for network in cmd.networkList!
{//check for your network ssid and set password
network.setConfidence(.high)
network.setPassword("yourpassword") //Set the WIFI password
hotspot.append(network)
}
let response = cmd.createResponse(NEHotspotHelperResult.success)
response.setNetworkList(hotspot)
response.deliver() } else if cmd.commandType == NEHotspotHelperCommandType.evaluate {
if let network = cmd.network {
let response = cmd.createResponse(NEHotspotHelperResult.success)
response.setNetwork(network)
response.deliver() //Respond back }
} else if cmd.commandType == NEHotspotHelperCommandType.authenticate {
//Perform custom authentication and respond back with success
// if all is OK
let response = cmd.createResponse(NEHotspotHelperResult.success)
response.deliver() //Respond back
}
2条答案
按热度按时间v09wglhw1#
你只需要使用以下代码:
字符串
brccelvz2#
使用NEHotspotNetwork函数
register
,您可以设置密码:字符串
您也可以使用网络配置文件的帮助下,苹果路由器2工具为您的已知网络。
在那里,您需要设置WiFi,然后在设备上安装NCP后,它会自动连接到上述网络。
但是你必须在服务器上托管该文件,因为我们不能在本地下载配置文件,并使用本地服务器,如GCDServer(已经尝试过)。