iOS 獲取當前連結WiFi名

weixin_33782386發表於2016-03-05

《一》匯入系統庫

#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);

}

相關文章