美文网首页
iOS-获取手机连接的WiFi信息

iOS-获取手机连接的WiFi信息

作者: BestVast | 来源:发表于2016-10-17 13:46 被阅读1439次
  • 1、引入头文件
#import <SystemConfiguration/CaptiveNetwork.h>
  • 2、获取到WiFi的信息,返回值为WiFi名字
-(void)viewDidLoad {
    [super viewDidLoad];
    UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
    btn.frame = CGRectMake(20, 100, 280, 50);
    btn.backgroundColor = [UIColor blueColor];
    [self.view addSubview:btn];
    [btn setTitle:@"查找WIFI" forState:UIControlStateNormal];
    [btn addTarget:self action:@selector(createButton:) forControlEvents:UIControlEventTouchUpInside];
}
-(void)createButton:(UIButton *)button
{
    [button setTitle:[NSString stringWithFormat:@"WIFI名字:%@", [self fetchSSIDInfo]] forState:UIControlStateNormal];
}
-(NSString *)fetchSSIDInfo
{
    NSString *currentSSID = @"Not Found";
    CFArrayRef myArray = CNCopySupportedInterfaces();
    if (myArray != nil){
        NSDictionary* myDict = (__bridge NSDictionary *) CNCopyCurrentNetworkInfo(CFArrayGetValueAtIndex(myArray, 0));
        if (myDict!=nil){
            currentSSID=[myDict valueForKey:@"SSID"];
/* myDict打印:{
       BSSID = "8a:25:93:57:14:24";
       SSID = sichou;
       SSIDDATA = <73696368 6f75>;
       }
*/
        } else {
            currentSSID=@"<<NONE>>";
        }
    } else {
        currentSSID=@"<<NONE>>";
    }
//    NSDictionary *info = nil;
//    for (NSString *ifnam in ifs) {
//        info = (__bridge NSDictionary *)CNCopyCurrentNetworkInfo((CFStringRef)CFBridgingRetain(ifnam));
//    }
    CFRelease(myArray);
    return currentSSID;
}

相关文章

网友评论

      本文标题:iOS-获取手机连接的WiFi信息

      本文链接:https://www.haomeiwen.com/subject/zxnayttx.html