How to get WiFi name without using CNCopyCurrentNetworkInfo on iOS 13?

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

Replies

it relies on being in the same WiFi network as iOS device.

I’m not 100% sure what you mean by this. Are you trying to configure your accessory? For example, set up the accessory so that it joins the user’s home network?

ps Your

CNCopyCurrentNetworkInfo
code is troubling. See this post for a better way.

Share and Enjoy

Quinn “The Eskimo!”
Apple Developer Relations, Developer Technical Support, Core OS/Hardware

let myEmail = "eskimo" + "1" + "@apple.com"