iPhone SDK 开发:如何判断WIFI链接
iPhone SDK提供了系统对话框用来判断是否有有效的WIFI链接, 这种情况已经在 iPhone SDK开发:如何显示WiFi提示 介绍过。
但是有时候如果打开了GPRS/Edge网络, 则不会弹出wifi对话框, 如果程序需要根据链接类型来传输不同的内容则需要判断当前有效链接是否为WIFI, 正好我的程序中用到就写了一个函数判断当前有效链接是否为WiFi
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 | 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; } |
主要工作原来是取得当前网络设备的名称, 如果包含“en0″或者”en1“则说明是wifi链接, 否则有可能是Edge等链接
转载自:FLYBLOG [http://www.flyblog.info]
本文链接地址:http://www.flyblog.info/catprogramming/335.html
相关文章
来看看老朋友啦!
老大你啥时候能教教我python?我是认真的,可以拜师的话,请email我一下!
python 很热门啊最近:)
最近愛風很火
struct ifaddrs
和
getifaddrs(struct ifaddrs &)
没有给出来啊