Hi,
I have an IoT app that uses CNCopyCurrentNetworkInfo to check current WiFi to determine if user switched WiFi. It's important to me because the IoT device is WiFi hardware and it relies on being in the same WiFi network as iOS device.
Any suggestions?
Current code is that:
guard let interfaces = CNCopySupportedInterfaces() else { return nil }
var wifiName: String? = nil
for i in 0..<CFArrayGetCount(interfaces) {
let interfaceName: UnsafeRawPointer = CFArrayGetValueAtIndex(interfaces, i)
let rec = unsafeBitCast(interfaceName, to: AnyObject.self)
let unsafeInterfaceData = CNCopyCurrentNetworkInfo("\(rec)" as CFString)
if unsafeInterfaceData != nil {
let interfaceData = unsafeInterfaceData! as NSDictionary
wifiName = interfaceData["SSID"] as? String
}
}
return wifiName