我从 StackOverflow 的另一篇文章中获取并修改的代码(编译时没有错误):
NSError *error;
NSArray *ifs = (NSArray *)CFBridgingRelease(CNCopySupportedInterfaces());
NSLog(@"%s: Supported interfaces: %@", __func__, ifs);
id info = nil;
for (NSString *ifnam in ifs)
{
info = (NSDictionary *)CFBridgingRelease(CNCopyCurrentNetworkInfo((__bridge CFStringRef)ifnam));
NSLog(@"%s: %@ => %@", __func__, ifnam, info);
if (info && [info count])
{
break;
}
}