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 B
  • 1,599
  • 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
  • 25,014
  • 12
  • 67
  • 90
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,397
  • 1
  • 24
  • 25
  • 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