检测iPhone当前网络是不是WiFi的代码

 BOOL IsWIFIConnection{
     BOOL ret = YES;
     struct ifaddrs * first_ifaddr, * current_ifaddr;
     NSMutableArray* activeInterfaceNames = [[NSMutableArray alloc] init];
     getifaddrs( &first_ifaddr );
     current_ifaddr = first_ifaddr;
    while( current_ifaddr!=NULL ){
          if( current_ifaddr->ifa_addr->sa_family==0x02 ){
             [activeInterfaceNames addObject:[NSString stringWithFormat:@"%s", current_ifaddr->ifa_name]];
         }
     current_ifaddr = current_ifaddr->ifa_next;
     }
ret = [activeInterfaceNames containsObject:@"en0"] || [activeInterfaceNames containsObject:@"en1"];
[activeInterfaceNames release];
return ret;
 
阅读更多
个人分类: iPhone
想对作者说点什么? 我来说一句

没有更多推荐了,返回首页

加入CSDN,享受更精准的内容推荐,与500万程序员共同成长!
关闭
关闭