ios獲取wifi熱點信息

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

+ (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,瞬間有種抓狂的感覺。

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

? ? ? ? 于是跟apple 申請... 得到回復(fù)如下:

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+ 的系統(tǒng)上拿到BSSID號了。

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

  • PLEASE READ THE FOLLOWING APPLE DEVELOPER PROGRAM LICENSE...
    念念不忘的閱讀 13,681評論 5 6
  • 照常上班,上午主要是回填,下午回填然后破水泥人行道?;貋沓赃^晚飯就上樓洗澡了,今天沒去打球?,F(xiàn)在已經(jīng)躺床上了...
    天空藍上閱讀 140評論 0 0
  • 我們在欣賞文藝片、話劇、歌劇、傳統(tǒng)舞、詩歌、繪畫、古典樂等人文作品的時候,是否一直無法領(lǐng)會創(chuàng)作者的情感、哲思與內(nèi)涵...
    王東呈閱讀 883評論 0 8
  • 醫(yī)院管理中的藥品審方流程。 1)患者持蓋章處方到藥房收方處審方確認。 2)收方人員接到患者提交的處方后,刷就診卡,...
    黃曉星閱讀 2,729評論 0 0

友情鏈接更多精彩內(nèi)容