直接上代码。。
//// ViewController.m// Reachability检测联网状态//// Created by chen on 15/2/15.// Copyright (c) 2015年 lanrw. All rights reserved.//#import "ViewController.h"#import "Reachability.h"@interface ViewController ()@property (nonatomic,strong) Reachability *myReachabity;@end@implementation ViewController- (Reachability *)myReachabity{ if(_myReachabity == nil){ _myReachabity = [Reachability reachabilityWithHostName:@"baidu.com"]; } return _myReachabity;}- (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view, typically from a nib.}- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{ switch ([self.myReachabity currentReachabilityStatus]) { case NotReachable: NSLog(@"没有联网"); break; case ReachableViaWiFi: NSLog(@"通过wifi联网"); break; case ReachableViaWWAN: NSLog(@"通过 2G/3G/4G联网"); break; }}@end