原文地址:http://www.cnblogs.com/geweb/p/CaptiveNetwork.html
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>
1
2
3
4
5
6
7
8
9
|
/*! @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. */ CFArrayRef CNCopySupportedInterfaces
( void )
__OSX_AVAILABLE_STARTING(__MAC_10_8,__IPHONE_4_1); |
通过CNCopySupportedInterfaces获取wifi列表,实际测试中返回数组中只有一个值,即当前连接的wifi。
1
2
3
4
5
6
7
8
9
10
11
12
13
14
|
-
( 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; } |