仿照器 获取到的 是空的,Network 里面的点子全都

     
工作碰着要求识别连接一定wifi热点,并收获该热门的BSSID的要求。记得以前搞过那么些需求,于是平昔用
Captive Network 来搞了。完结格局如下:

iOS 获取ssid,ios获取ssid

– (NSString *)fetchSSIDInfo

{

   NSString *ssid = nil;

    NSArray *ifs = (__bridge_transfer
id)CNCopySupportedInterfaces();

    for (NSString *ifnam in ifs) {

        NSDictionary *info = (__bridge_transfer
id)CNCopyCurrentNetworkInfo((__bridge CFStringRef)ifnam);

        if (info[@”SSID”]) {

            ssid = info[@”SSID”];

        }

    }

        return ssid;

}

 注意:真机才好使, 模拟器 获取到的 是空的。

http://www.bkjia.com/IOSjc/1083521.htmlwww.bkjia.comtruehttp://www.bkjia.com/IOSjc/1083521.htmlTechArticleiOS 获取ssid,ios获取ssid – (NSString
*)fetchSSIDInfo { NSString *ssid = nil; NSArray *ifs =
(__bridge_transfer id)CNCopySupportedInterfaces(); for (NSString
*ifnam in ifs) {…

+ (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号了。

相关文章