获取wifi信息

最近有个项目需要获取手机附近wifi列表,查了许多资料发现,现在只能查到wifi的SSID,并且用到的是私有api,无法通过app store审核,这里记录一下,方便学习,新手勿喷,欢迎大神指教(wifi信息获取需要真机测试才能获取数据)

导入系统头文件

#import <SystemConfiguration/CaptiveNetwork.h>

 

实现代码

NSString *ssid = @"Not Found";
NSString *macIp = @"Not Found";
CFArrayRef myArray = CNCopySupportedInterfaces();
if (myArray != nil) {
CFDictionaryRef myDict = CNCopyCurrentNetworkInfo(CFArrayGetValueAtIndex(myArray, 0));
if (myDict != nil) {
NSDictionary *dict = (NSDictionary*)CFBridgingRelease(myDict);

ssid = [dict valueForKey:@"SSID"];
macIp = [dict valueForKey:@"BSSID"];
}
}
UIAlertView *av = [[UIAlertView alloc] initWithTitle:ssid
message:macIp
delegate:nil
cancelButtonTitle:nil
otherButtonTitles:@"OK", nil];
[av show];

 

posted on 2014-12-16 11:01  FannyLi  阅读(255)  评论(0编辑  收藏  举报

导航