Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

iOS

ivan hernandez
PLUS
ivan hernandez
Courses Plus Student 2,298 Points

IOS7 Get SSID and BSSid

I´m having problems getting SSID, I´m using this code but I don't get anything ...

-(void)getCurrentWifi{
(NSString *)GetCurrentWifiHotSpotName{
    NSString *wifiname = nil;
    NSArray *ifs = (__bridge_transfer id)CNCopySupportedInterfaces();
    for (NSString *ifnam in ifs) {
        NSDictionary *info = (__bridge_transfer id)CNCopyCurrentNetworkInfo((__bridge CFStringRef)ifnam);
        NSLog(@"informacion: %@", info);
        if (info[@"SSID"]) {
            wifiname = info[@"SSID"];
        }
    }

Ben Jakuben , Amit Bijlani , any tips??? what is wrong with this code???

thx

4 Answers

Stefan Jansen
Stefan Jansen
8,974 Points

I use this code, it works like a charm. :)

- (NSString *)getCurrentWiFiName
{
    NSString *ssid = @"NO WIFI!";
    NSArray *ifs = (__bridge_transfer id)CNCopySupportedInterfaces();
    if ([ifs count] > 0) {
        for (NSString *ifname in ifs) {
            NSDictionary *info = (__bridge_transfer id)CNCopyCurrentNetworkInfo((__bridge CFStringRef)ifname);

            if (info[@"SSID"]) {
                ssid = info[@"SSID"];
            }
        }
    }

    return ssid;
}
ivan hernandez
PLUS
ivan hernandez
Courses Plus Student 2,298 Points

Hi there, I used that code but I get IFS=null ... But I guess the problems is with the simulardor I need to try it in phone to see what happens