当前位置 : 主页 > 手机开发 > ios >

IOS 获取已连接的wifi信息的实现代码

来源:互联网 收集:自由互联 发布时间:2021-05-10
IOS 获取已连接的wifi信息的实现代码 首先需要 #import SystemConfiguration/CaptiveNetwork.h + (id)fetchSSIDInfo { NSArray *ifs = (id)CNCopySupportedInterfaces(); NSLog(@"%s: Supported interfaces: %@", __func__, ifs); id info =

IOS 获取已连接的wifi信息的实现代码

首先需要   #import <SystemConfiguration/CaptiveNetwork.h>

+ (id)fetchSSIDInfo 
{ 
  NSArray *ifs = (id)CNCopySupportedInterfaces(); 
  NSLog(@"%s: Supported interfaces: %@", __func__, ifs); 
  id info = nil; 
  for (NSString *ifnam in ifs) { 
    info = (id)CNCopyCurrentNetworkInfo((CFStringRef)ifnam); 
    NSLog(@"%@ => %@", ifnam, info); 
    if (info && [info count]) { break; } 
    [info release]; 
  } 
  [ifs release]; 
  return [info autorelease]; 
} 

ARC 版本:

+ (id)fetchSSIDInfo { 
  NSArray *ifs = (__bridge_transfer id)CNCopySupportedInterfaces(); 
  NSLog(@"%s: Supported interfaces: %@", __func__, ifs); 
  id info = nil; 
  for (NSString *ifnam in ifs) { 
    info = (__bridge_transfer id)CNCopyCurrentNetworkInfo((__bridge CFStringRef)ifnam); 
    NSLog(@"%@ => %@", ifnam, info); 
    if (info && [info count]) { break; } 
  } 
  return info; 
} 

以上就是IOS 获取已连接的wifi信息的实例,如有疑问请留言或者到本站社区交流讨论,感谢阅读,希望能帮助到大家,谢谢大家对本站的支持!

网友评论