获取Wi-Fi信息iOS

获取Wi-Fi信息(名称、Mac 地址、信号强度)#import SystemConfiguration/SystemConfiguration.h#import SystemConfiguration/CaptiveNetwork.h-(NSString *)getWifiName{NSString *wifiName = nil;CFArrayRe...

 

 

获取Wi-Fi信息(名称、Mac 地址、信号强度)


#import <SystemConfiguration/SystemConfiguration.h>

#import <SystemConfiguration/CaptiveNetwork.h>



-(NSString *)getWifiName { NSString *wifiName = nil; CFArrayRef wifiInterfaces = CNCopySupportedInterfaces(); if (!wifiInterfaces) { return @"unknow"; } 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);
//networkInfo为一个字典,包含Wi-Fi名字、Mac 地址、信号强度

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

 

 

在iOS9之后获取Wi-Fi相关信息,需要拥有对应权限的证书。

xcode程序中也要打开capabilities中access wifi information开关

 

本文标题为:获取Wi-Fi信息iOS

基础教程推荐