首页 > 学院 > 开发设计 > 正文

ios获取当前wifi名称

2019-11-14 20:34:45
字体:
来源:转载
供稿:网友

ios5之前可以通过读取配置文件获取,ios5以后苹果修改wifi列表文件位置,只有root权限才可以读取.

ios4:/System/Library/SystemConfiguration/WiFiManager.bundle/WiFiManager

ios5:/System/Library/SystemConfiguration/ipConfiguration.bundle/IPConfiguration

 

官方的API没有提供获取扫描所有wifi列表,相近功能的只有CaptiveNetwork,获取当前wifi的名称。

引用头文件<SystemConfiguration/CaptiveNetwork.h>

/*! @function CNCopySupportedInterfaces @discussion copies a list of all interfaces CaptiveNetworkSupport is monitoring. @result An array of CFStringRef- BSD interface names.	 Returns NULL if an error was encountered.	 You MUST release the returned value. */CFArrayRefCNCopySupportedInterfaces	(void)				__OSX_AVAILABLE_STARTING(__MAC_10_8,__IPHONE_4_1);

通过CNCopySupportedInterfaces获取wifi列表,实际测试中返回数组中只有一个值,即当前连接的wifi。

 

- (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;}    

 


发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表