iOS 获取当前链接WiFi名
2016-03-05 本文已影响2698人
無春不欢
《一》导入系统库
#import<SystemConfiguration/CaptiveNetwork.h>
#import<SystemConfiguration/SystemConfiguration.h>
#import<CoreFoundation/CoreFoundation.h>
《二》获取当前链接的WiFi名称方法,需要真机才能测试!模拟器返回 空
- (void)GetWifiName{
NSString *wifiName = @"Not Found";
CFArrayRef myArray = CNCopySupportedInterfaces();
if (myArray != nil) {
CFDictionaryRef myDict =CNCopyCurrentNetworkInfo(CFArrayGetValueAtIndex(myArray, 0));
if (myDict != nil) {
NSDictionary *dict = (NSDictionary*)CFBridgingRelease(myDict);
wifiName = [dict valueForKey:@"SSID"];
}
NSLog(@"wifiName:%@", wifiName);
}