Search code examples
iosnetworkingnetwork-programmingssidcaptivenetwork

Simple Code to get the SSID from Network


Hi I am Looking for a Simple Code to read the SSID, I found a lot of Information about "SystemConfiguration/CaptiveNetwork.h" but how can I use it, i don't understand it. Sorry I am a new Objective-C programmer. Do you have a good example or tutorial to understand it. I tried Reachable from Apple but they don't work with Dictionaries.

Thanks for help


Solution

  • Thank you @helming, here it is, this way it won't compile into the Simulator binary + added calls to CFRelease:

    #if !TARGET_IPHONE_SIMULATOR
        CFArrayRef interfaces = CNCopySupportedInterfaces();
        CFDictionaryRef networkInfo = CNCopyCurrentNetworkInfo(CFArrayGetValueAtIndex(interfaces, 0));
        NSString *ssid = CFDictionaryGetValue(networkInfo, @"SSID");
        CFRelease(interfaces);
        CFRelease(networkInfo);
    #endif