ios獲取wifi熱點信息

? ? ? 工作遇到需要識別連接固定wifi熱點,并獲取該熱點的BSSID的需求。記得以前搞過這個需求,于是直接用 Captive Network 來搞了。實現方法如下:

+ (NSString *)currentWifiBSSID

{

? ? ? ?NSString *bssid = nil;

? ? ? ?NSArray *ifs = (__bridge? id)CNCopySupportedInterfaces();

? ? ? ?for (NSString *ifname in ifs) {

? ? ? ? ? NSDictionary *info = (__bridge id)CNCopyCurrentNetworkInfo((__bridge CFStringRef)ifname);

? ? ? ? ? ? if (info[@"BSSID"])

? ? ? ? ? ? ? ? ? ? ? ? {

? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? bssid = info[@"BSSID"];

? ? ? ? ? ? ? ? ? ? ? ? ?}

? ? ? ? ? ? ? ?}

? ? ? ? ? ? ? ?return bssid;

? }

? ? ? ?這個方法在ios9之前一直是work的,但郁悶的是在ios9+上 Captive Network 里面的方法全都Deprecated,瞬間有種抓狂的感覺。

? ? ? ?后來在網上一番搜索,發現需要NEHotspotHelper APIs使用權限的entitlement。見http://stackoverflow.com/questions/31555640/how-to-get-wifi-ssid-in-ios9-after-captivenetwork-is-depracted-and-calls-for-wif

? ? ? ? 于是跟apple 申請... 得到回復如下:

Hello,

Thank you for your interest in the Network Extension framework. Unfortunately, these APIs are not designed for the use you’ve identified. We’ll let you know if that changes.

The NEHotspotHelper APIs are meant to be used by hotspot network implementers to facilitate connections to known wireless networks that they manage. ... If your app needs to verify or retrieve information about the currently connected WiFi network, the following Captive Network APIs, while deprecated, have been re-enabled in iOS 9 instead.

CNCopySupportedInterfaces

CNCopyCurrentNetworkInfo

https://developer.apple.com/library/ios/documentation/SystemConfiguration/Reference/CaptiveNetworkRef/

Please visit developer.apple.com to download the latest build.

? ? ? ?得到提示,升級xcode到最新版本,再build,果然可以在ios9.0+ 的系統上拿到BSSID號了。

最后編輯于
?著作權歸作者所有,轉載或內容合作請聯系作者
平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發布,文章內容僅代表作者本人觀點,簡書系信息發布平臺,僅提供信息存儲服務。

推薦閱讀更多精彩內容