I have an app that connects to an external device using WIFI and I used to validate that the iPhone is connected to the device by checking the WIFI SSID. This was blocked when iOS 13 was released and I fixed it by requesting location permission to get the SSID.
I tried now with iOS 14 beta with location service enabled but couldn't get the WIFI SSID, however the same code works with iOS 13.
Here is the log I get when I call CNCopyCurrentNetworkInfo
nehelper sent invalid result code [1] for Wi-Fi information request
nehelper sent invalid response: <dictionary: 0x1e815f3e0> { count = 1, transaction: 0, voucher = 0x0, contents =
"XPCErrorDescription" => <string: 0x1e815f548> { length = 18, contents = "Connection invalid" }
}
nehelper sent invalid response for Wi-Fi information request: <dictionary: 0x1e815f3e0> { count = 1, transaction: 0, voucher = 0x0, contents =
"XPCErrorDescription" => <string: 0x1e815f548> { length = 18, contents = "Connection invalid" }
Any idea how to solve this issue? Thanks
Update: it works only if the precise location is on when requesting location access
I used following method to achieve this in iOS 14 and older versions.
import NetworkExtension
func getNetworkInfo(compleationHandler: @escaping ([String: Any])->Void){
var currentWirelessInfo: [String: Any] = [:]
if #available(iOS 14.0, *) {
NEHotspotNetwork.fetchCurrent { network in
guard let network = network else {
compleationHandler([:])
return
}
let bssid = network.bssid
let ssid = network.ssid
currentWirelessInfo = ["BSSID ": bssid, "SSID": ssid, "SSIDDATA": "<54656e64 615f3443 38354430>"]
compleationHandler(currentWirelessInfo)
}
}
else {
#if !TARGET_IPHONE_SIMULATOR
guard let interfaceNames = CNCopySupportedInterfaces() as? [String] else {
compleationHandler([:])
return
}
guard let name = interfaceNames.first, let info = CNCopyCurrentNetworkInfo(name as CFString) as? [String: Any] else {
compleationHandler([:])
return
}
currentWirelessInfo = info
#else
currentWirelessInfo = ["BSSID ": "c8:3a:35:4c:85:d0", "SSID": "Tenda_4C85D0", "SSIDDATA": "<54656e64 615f3443 38354430>"]
#endif
compleationHandler(currentWirelessInfo)
}
}
Get current network information :
var currentNetworkInfo: [String: Any] = [:]
getNetworkInfo { (wifiInfo) in
currentNetworkInfo = wifiInfo
}
CNCopyCurrentNetworkInfo is deprecated for ios14 CNCopyCurrentNetworkInfo (CFStringRef interfaceName) API_DEPRECATED_WITH_REPLACEMENT("[NEHotspotNetwork fetchCurrentWithCompletionHandler:]", ios(4.1, API_TO_BE_DEPRECATED), macCatalyst(14.0, API_TO_BE_DEPRECATED))
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With