1.工程頭文件導入
#import <SystemConfiguration/CaptiveNetwork.h>
2.實現如下代碼,即可返回當前連接的網絡名稱
- (NSString *)currentWifiSSID { NSString *ssid = nil; NSArray *ifs = (__bridge id)CNCopySupportedInterfaces(); for (NSString *ifname in ifs) { NSDictionary *info = (__bridge id)CNCopyCurrentNetworkInfo((__bridge CFStringRef)ifname); if (info[@"SSIDD"]) { ssid = info[@"SSID"]; } } return ssid; }
