根据我的理解,您可以使用以下代码实现此目的
let targetSsid = getCurrentSSID()
let targetAnnotation: String = targetSsid!
//let options: [String: NSObject] = [kNEHotspotHelperOptionDisplayName : targetAnnotation as NSObject]
//let queue: DispatchQueue = DispatchQueue(label: "com.myapp.appname", attributes: DispatchQueue.Attributes.concurrent)
NSLog("Started wifi list scanning.")
let options: [String: NSObject] = [
kNEHotspotHelperOptionDisplayName: targetAnnotation as NSString
]
let queue = DispatchQueue(label: "com.example.test")
let isAvailable = NEHotspotHelper.register(options: options, queue: queue) { (command) in
switch command.commandType {
case .evaluate,
.filterScanList:
let originalNetworklist = command.networkList ?? []
let networkList = originalNetworklist.compactMap { network -> NEHotspotNetwork? in
print("networkName: \(network.ssid); strength: \(network.signalStrength)")
if network.ssid == targetSsid {
network.setConfidence(.high)
//network.setPassword(targetPassword)
return network
}
return nil
}
let response = command.createResponse(.success)
response.setNetworkList(networkList)
response.deliver()
default:
break
}
}
唯一的问题是您必须在 wifi 设置页面获取所有可用 SSID 的列表及其信号强度。