今天给大家分享oc如何判断网络,首先大家先去下载这个已经封装的好的类,到时咱们就用它来判断网络,很简单哦,这是链接http://pan.baidu.com/s/1o6vAUam
下载好了之后解压,然后拖入到你的项目之中,然后再AppDelegate.m中导入头文件
#import "Reachability.h"
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
Reachability *reachability = [Reachability reachabilityWithHostName:@"www.apple.com"];
switch ([reachability currentReachabilityStatus]) {
case NotReachable:
{
UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"当前没有网络连接哦!" message:nil delegate:self cancelButtonTitle:@"确定" otherButtonTitles: nil];
[alert show];
[alert release];
}
break;
case ReachableViaWiFi:
NSLog(@"wifi连接");
break;
case ReachableViaWWAN:
NSLog(@"蜂窝数据");
break;
default:
break;
}
return YES;
}