-(id)fetchSSIDInfo
{
NSArray *ifs = (id)CNCopySupportedInterfaces();
NSLog(@"%s: Supported interfaces: %@", __func__, ifs);
id info = nil;
for (NSString *ifnam in ifs) {
info = (id)CNCopyCurrentNetworkInfo((CFStringRef)ifnam);
if (info && [info count]) {
break;
}
[info release];
}
[ifs release];
return [info autorelease];
}
- (NSString *)currentWifiSSID {
// Does not work on the simulator.
NSString *ssid = nil;
NSArray *ifs = ( id)CNCopySupportedInterfaces();
NSLog(@"ifs:%@",ifs);
for (NSString *ifnam in ifs) {
NSDictionary *info = (id)CNCopyCurrentNetworkInfo((CFStringRef)ifnam);
NSLog(@"dici:%@",[info allKeys]);
if (info[@"SSIDD"]) {
ssid = info[@"SSID"];
}
}
return ssid;
}
- (void)viewDidLoad
{
[super viewDidLoad];
tempLabel=[[UILabel alloc]initWithFrame:CGRectMake(50, 40, 200, 40)];
tempLabel.textAlignment=NSTextAlignmentCenter;
[self.view addSubview:tempLabel];
NSDictionary *ifs = [self fetchSSIDInfo];
NSString *ssid = [[ifs objectForKey:@"SSID"] lowercaseString];
tempLabel.text=ssid;
}