在Xcode10 iOS12 获取WiFi名称失败问题

2018-11-22  本文已影响0人  Kingiiyy_iOS

前言:

项目中遇到了这个问题.记录一下这个问题并不是针对iOS12才会出现.而已升级了Xcode10才会有..哈哈

原获取wifi名代码

//引入头
#import <SystemConfiguration/CaptiveNetwork.h>  

+ (NSString *)getWifiName{
    
    NSString *wifiName = nil;
    CFArrayRef wifiInterfaces = CNCopySupportedInterfaces();
    NSArray *interfaces = (__bridge NSArray *)wifiInterfaces;

    for (NSString *interfaceName in interfaces) {

        CFDictionaryRef dictRef = CNCopyCurrentNetworkInfo((__bridge CFStringRef)(interfaceName));
        if (dictRef) {
            NSDictionary *networkInfo = (__bridge NSDictionary *)dictRef;

            wifiName = [networkInfo objectForKey:(__bridge NSString *)kCNNetworkInfoKeySSID];
            CFRelease(dictRef);
        }
    }
    CFRelease(wifiInterfaces);

    return wifiName;
}

发现Xcode10跑这一段代码已经获取不到了..GG

解决办法

WechatIMG2.jpeg

Access wifi information 设置为NO

到这里就好了.同志们赶紧去运行试试吧

上一篇下一篇

猜你喜欢

热点阅读