iOS學習筆記 5 —— 獲取當前連接的Wi-fi信息

#import <SystemConfiguration/CaptiveNetwork.h>
#import "ViewController.h"

@interface ViewController ()

@end

@implementation ViewController

- (void)viewDidLoad
{
    [self fetchSSIDInfo];
    [super viewDidLoad];
	// Do any additional setup after loading the view, typically from a nib.
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (id)fetchSSIDInfo {
    NSArray *ifs = (__bridge_transfer id)CNCopySupportedInterfaces();
    NSLog(@"Supported interfaces: %@", ifs);
    id info = nil;
    NSLog(@"start...");
    for (NSString *ifnam in ifs) {
        info = (__bridge_transfer id)CNCopyCurrentNetworkInfo((__bridge CFStringRef)ifnam);
        NSLog(@"%@ => %@", ifnam, info);  //單個數據info[@"SSID"]; info[@"BSSID"];
        if (info && [info count]) { break; }
    }
    NSLog(@"end.");
    return info;
}

@end


2014-05-08 11:03:09.679 WifiTest2[22988:60b] Supported interfaces: (
    en0
)
2014-05-08 11:03:09.683 WifiTest2[22988:60b] start...
2014-05-08 11:03:09.689 WifiTest2[22988:60b] en0 => {
    BSSID = "78:54:2e:f9:b5:52";
    SSID = "D-Link_DIR_615";
    SSIDDATA = <442d4c69 6e6b5f44 49525f36 3135>;
}
2014-05-08 11:03:09.690 WifiTest2[22988:60b] end.


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章