// 2. 添加SystemConfiguration.framework框架
// 3. 引入Reachibility.h文件
// 4. 代码操作:
// 判断当前为那种网络
Reachability *reachability = [Reachability reachabilityWithHostName:@"www.apple.com"];
switch ([reachability currentReachabilityStatus]) {
case NotReachable:
NSLog(@"无网络连接");
break;
case ReachableViaWiFi:
NSLog(@"wifi连接");
break;
case ReachableViaWWAN:
NSLog(@"蜂窝数据");
break;
default:
break;
}
#pragma mark 判断时候为wifi
- (BOOL)isEnableWIFI
{
return ([[Reachability reachabilityForLocalWiFi] currentReachabilityStatus] != NotReachable);
}
#pragma mark 判断时候为3G
- (BOOL)isEnable3G
{
return ([[Reachability reachabilityForInternetConnection] currentReachabilityStatus] !=NotReachable);
}
#pragma mark 判断是否有网络连接
- (BOOL)isNetwork
{
if (([[Reachability reachabilityForLocalWiFi] currentReachabilityStatus] == NotReachable) &&
([[Reachability reachabilityForInternetConnection] currentReachabilityStatus] == NotReachable)) {
return NO;
}
return YES;
}