iPhone get SSID without private library

后端 未结 9 928
[愿得一人]
[愿得一人] 2020-11-22 06:00

I have a commercial app that has a completely legitimate reason to see the SSID of the network it is connected to: If it is connected to a Adhoc network for a 3rd party har

9条回答
  •  执念已碎
    2020-11-22 06:28

    This works for me on the device (not simulator). Make sure you add the systemconfiguration framework.

    #import 
    
    + (NSString *)currentWifiSSID {
        // Does not work on the simulator.
        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;
    }
    

提交回复
热议问题