使用Reachability类判断iOS设备的当前网络连接类型
(1).下载https://developer.apple.com/library/ios/samplecode/Reachability/Reachability.zip
(2).拖reachability.h,reachability.m入工程(库非ARC)
ARC:-fno-objc-arc
(3).导入SystemConfiguration.framework
(4).用法
-(NSString*)getNetType { NSString*result; Reachability*r=[ReachabilityreachabilityWithHostName:@"www.baidu.com"]; NSLog(@" ====:%i",[rcurrentReachabilityStatus]); switch([rcurrentReachabilityStatus]){ caseNotReachable://没有网络连接 result=@"没有网络连接"; break; caseReachableViaWWAN://使用3G网络 result=@"3g"; break; caseReachableViaWiFi://使用WiFi网络 result=@"wifi"; break; } NSLog(@"caseReachableViaWWAN=%i",ReachableViaWWAN); NSLog(@"caseReachableViaWiFi=%i",ReachableViaWiFi); returnresult; }