I want the information about the wifi with which my iPhone is connected. I have already added Access WiFi Information
, Hotspot Configuration
and Network Extension
under Signing & Capabilities
also Included UIBackgroundModes array containing network-authentication
in the application Info.plist.
After all this, I also tried the below solution but always got empty or null as wifi SSID.
- https://stackoverflow.com/a/42022195/11724588
- https://stackoverflow.com/a/32767659/11724588
- https://stackoverflow.com/a/5198968/11724588
Code:
func getInterfaces() -> Bool {
guard let unwrappedCFArrayInterfaces = CNCopySupportedInterfaces() else {
print("this must be a simulator, no interfaces found")
return false
}
guard let swiftInterfaces = (unwrappedCFArrayInterfaces as NSArray) as? [String] else {
print("System error: did not come back as array of Strings")
return false
}
for interface in swiftInterfaces {
print("Looking up SSID info for \(interface)") // en0
guard let unwrappedCFDictionaryForInterface = CNCopyCurrentNetworkInfo(interface as CFString) else {
print("System error: \(interface) has no information")
return false
}
guard let SSIDDict = (unwrappedCFDictionaryForInterface as NSDictionary) as? [String: AnyObject] else {
print("System error: interface information is not a string-keyed dictionary")
return false
}
for d in SSIDDict.keys {
print("\(d): \(SSIDDict[d]!)")
}
}
return true
}
Output logs:
Looking up SSID info for en0
2020-02-25 14:22:53.640018+0530 Runner[422:22122] [] nehelper sent invalid result code [1] for Wi-Fi information request
System error: en0 has no information