iOS 獲取Wifi的SSID及MAC地址
阿新 • • 發佈:2019-02-02
匯入系統標頭檔案
#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];