? ? ? 工作遇到需要識別連接固定wifi熱點(diǎn),并獲取該熱點(diǎn)的BSSID的需求。記得以前搞過這個需求,于是直接用 Captive Network 來搞了。實(shí)現(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
Please visit developer.apple.com to download the latest build.
? ? ? ?得到提示,升級xcode到最新版本,再build,果然可以在ios9.0+ 的系統(tǒng)上拿到BSSID號了。