GET SSID problems with CNCopyCurrentNetworkInfo

Hello, I try to get the WiFi SSID, from the iPhone, with the CNCopyCurrentNetworkInfo function. I become as interface "en0" and the error message:

[43481:8106022] [] nehelper sent invalid result code [1] for Wi-Fi information request

I don't no where is the problem. My function for the SSID request is this one:


            for i in 0..<CFArrayGetCount(interface) {

              let interfaceName: UnsafeRawPointer = CFArrayGetValueAtIndex(interface, i)

                print(interface)

              let rec = unsafeBitCast(interfaceName, to: AnyObject.self)

              if let unsafeInterfaceData = CNCopyCurrentNetworkInfo("\(rec)" as CFString), let interfaceData = unsafeInterfaceData as? [String : AnyObject] {

                // connected wifi

                print("BSSID: \(interfaceData["BSSID"]), SSID: \(interfaceData["SSID"]), SSIDDATA: \(interfaceData["SSIDDATA"])")

              } else {

                // not connected wifi

              }

            }

          }

if you have any idea where is my problem pleas help me.

With best regards Niklas

Four things:

  • CNCopyCurrentNetworkInfo has been deprecated in favour of +[NEHotspotNetwork fetchCurrentWithCompletionHandler:]. If you’re building for a modern system, use that instead.

  • That method has strict authorisation requirements. For details, see the doc comments in <NetworkExtension/NEHotspotNetwork.h>.

  • CNCopyCurrentNetworkInfo has similar restrictions, which are listed in the official documentation.

  • Your CNCopyCurrentNetworkInfo code is definitely off in the weeds (you do not need to use unsafeBitCast(_:to:) here. If you continue using CNCopyCurrentNetworkInfo, use the code from this post.

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

GET SSID problems with CNCopyCurrentNetworkInfo
 
 
Q