1.导入:Reachability 文件
2.导入:Reachability的头文件
3.复制代码:
+ (BOOL) isConnectionAvailable{
BOOL isExistenceNetwork = YES;
Reachability *reach = [Reachability reachabilityWithHostName:@"www.apple.com"];
switch ([reach currentReachabilityStatus]) {
case NotReachable:
isExistenceNetwork = NO;
//NSLog(@"notReachable");
break;
case ReachableViaWiFi:
isExistenceNetwork = YES;
//NSLog(@"WIFI");
break;
case ReachableViaWWAN:
isExistenceNetwork = YES;
//NSLog(@"3G");
break;
}
if (!isExistenceNetwork) {
[YZTools toastMake:@"没有网络" isPush:NO];
return NO;
}
return isExistenceNetwork;
}