2

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

pratik bhiyani
  • 1,603
  • 1
  • 15
  • 32
J0k3R
  • 303
  • 1
  • 14

2 Answers2

1
CFArrayRef myArray = CNCopySupportedInterfaces();
CFDictionaryRef myDict = CNCopyCurrentNetworkInfo(CFArrayGetValueAtIndex(myArray, 0));
NSString *ssid = CFDictionaryGetValue(myDict, @"SSID");
Cyrille
  • 24,746
  • 12
  • 65
  • 89
J0k3R
  • 303
  • 1
  • 14
  • 1
    Don't forget to release the copied Core Foundation objects, ARC won't take care of that for you. `CFRelease(myArray); CFRelease(myDict);` – Tom Susel Feb 04 '14 at 10:58
  • Also notice this does not work on the simulator, `CNCopySupportedInterfaces()` will return null – Tom Susel Feb 04 '14 at 11:04
  • But how can i find the ipaddress for the router? – J0k3R Mar 04 '14 at 07:29
  • [dicInfo setObject:[NSString stringWithFormat:@"%@",ipaddr] forKey:@"IPAddress"]; https://github.com/bcsphere/wifi/blob/master/src/ios/BCWifi.m Note: To test this you will need a device, simulator wouldn't work. – Abhijeet Jan 26 '15 at 06:17
1

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
Tom Susel
  • 3,207
  • 1
  • 23
  • 23
  • Can you tell me how i can get the ip Address from the Router,gateway? – J0k3R Mar 01 '14 at 08:10
  • For the ip, see this thread: http://stackoverflow.com/questions/7072989/iphone-ipad-osx-how-to-get-my-ip-address-programmatically – Tom Susel Mar 04 '14 at 09:26