獲取網絡數據類型,須要導入一個蘋果api文件:Reachability(能夠直接在官方上下載),裏面的枚舉類型就是對應網絡類型 kSCNetworkReachabilityFlagsIsWWAN、 kSCNetworkReachabilityFlagsReachable、kSCNetworkReachabilityFlagsTransientConnection、 kSCNetworkReachabilityFlagsConnectionRequired kSCNetworkReachabilityFlagsConnectionOnTraffic、kSCNetworkReachabilityFlagsInterventionRequired、 kSCNetworkReachabilityFlagsConnectionOnDemand、 kSCNetworkReachabilityFlagsIsLocalAddress、kSCNetworkReachabilityFlagsIsDirectapi
自定義的一個返回方法:網絡
#pragma mark - 判斷網絡類型 + (NSString *)getNetconnType{ NSString *netconnType = @""; Reachability *reach = [Reachability reachabilityWithHostName:@"www.apple.com"]; switch ([reach currentReachabilityStatus]) { case NotReachable:// 沒有網絡 { netconnType = @"no_network"; } break; case ReachableViaWiFi:// Wifi { netconnType = @"Wifi"; } break; case ReachableViaWWAN:// 手機自帶網絡 { // 獲取手機網絡類型 CTTelephonyNetworkInfo *info = [[CTTelephonyNetworkInfo alloc] init]; NSString *currentStatus = info.currentRadioAccessTechnology; if ([currentStatus isEqualToString:@"CTRadioAccessTechnologyGPRS"]) { netconnType = @"GPRS"; }else if ([currentStatus isEqualToString:@"CTRadioAccessTechnologyEdge"]) { netconnType = @"2.75G EDGE"; }else if ([currentStatus isEqualToString:@"CTRadioAccessTechnologyWCDMA"]){ netconnType = @"3G"; }else if ([currentStatus isEqualToString:@"CTRadioAccessTechnologyHSDPA"]){ netconnType = @"3.5G HSDPA"; }else if ([currentStatus isEqualToString:@"CTRadioAccessTechnologyHSUPA"]){ netconnType = @"3.5G HSUPA"; }else if ([currentStatus isEqualToString:@"CTRadioAccessTechnologyCDMA1x"]){ netconnType = @"2G"; }else if ([currentStatus isEqualToString:@"CTRadioAccessTechnologyCDMAEVDORev0"]){ netconnType = @"3G"; }else if ([currentStatus isEqualToString:@"CTRadioAccessTechnologyCDMAEVDORevA"]){ netconnType = @"3G"; }else if ([currentStatus isEqualToString:@"CTRadioAccessTechnologyCDMAEVDORevB"]){ netconnType = @"3G"; }else if ([currentStatus isEqualToString:@"CTRadioAccessTechnologyeHRPD"]){ netconnType = @"HRPD"; }else if ([currentStatus isEqualToString:@"CTRadioAccessTechnologyLTE"]){ netconnType = @"4G"; } } break; default: break; } return netconnType; }