iOS 获得当前连接的wifi的名字

来源:互联网 发布:java maven 配置 编辑:程序博客网 时间:2024/06/06 06:57

+ (NSString *)getWifiName

{

    NSString *wifiName = nil;

   
    CFArrayRef wifiInterfaces = CNCopySupportedInterfaces();

   
    if (!wifiInterfaces) {

        return nil;

    }

   
    NSArray *interfaces = (__bridge NSArray *)wifiInterfaces;

   
    for (NSString *interfaceName in interfaces) {

        CFDictionaryRef dictRef = CNCopyCurrentNetworkInfo((__bridge CFStringRef)(interfaceName));

       
        if (dictRef) {

            NSDictionary *networkInfo = (__bridge NSDictionary *)dictRef;

            NSLog(@"network info -> %@", networkInfo);

            wifiName = [networkInfo objectForKey:(__bridge NSString *)kCNNetworkInfoKeySSID];

           
            CFRelease(dictRef);

        }

    }

   
    CFRelease(wifiInterfaces);

    return wifiName;

}

 

出处真的忘了,为了开源,委屈原作者了

0 0