How do I use CaptiveNetwork to get the current WiFi Hotspot Name

后端 未结 4 2041
迷失自我
迷失自我 2020-11-28 04:17

I need to get the name of the currently connected Wi-Fi hotspot, e.g. \"BT OpenZone\"

I have been told it can be done with CaptiveNetwork specifically CNCopyCurrentN

4条回答
  •  感情败类
    2020-11-28 04:59

    Easy to use code snippet(method):

    • Add SystemConfiguration.framework

    • import < SystemConfiguration/CaptiveNetwork.h>

    • use the below method

      + (NSString *)GetCurrentWifiHotSpotName {
      
          NSString *wifiName = nil;
          NSArray *ifs = (__bridge_transfer id)CNCopySupportedInterfaces();
          for (NSString *ifnam in ifs) {
              NSDictionary *info = (__bridge_transfer id)CNCopyCurrentNetworkInfo((__bridge CFStringRef)ifnam);
      
              NSLog(@"info:%@",info);
      
              if (info[@"SSID"]) {
                  wifiName = info[@"SSID"];
              }
          }
          return wifiName;
      }
      

提交回复
热议问题