网络:监听网络(使用Reachability框架)
2016-04-19 14:29
447 查看
#import "ViewController.h" #import "Reachability.h" @interface ViewController () @property (nonatomic, strong) Reachability *bility; @end @implementation ViewController - (void)viewDidLoad { [super viewDidLoad]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(networkChangeNotification) name:kReachabilityChangedNotification object:nil]; [self.bility startNotifier]; } - (void)networkChangeNotification { NSLog(@"网络发生改变"); NetworkStatus status = self.bility.currentReachabilityStatus; switch (status) { case kNotReachable: NSLog(@"没有网络你玩个毛"); break; case kReachableViaWiFi: NSLog(@"不用钱的随便玩"); break; case kReachableViaWWAN: NSLog(@"土豪请随意"); break; } } - (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event { NetworkStatus status = self.bility.currentReachabilityStatus; switch (status) { case kNotReachable: NSLog(@"没有网络你玩个毛"); break; case kReachableViaWiFi: NSLog(@"不用钱的随便玩"); break; case kReachableViaWWAN: NSLog(@"土豪请随意"); break; } } - (Reachability *)bility { if (_bility == nil) { _bility = [Reachability reachabilityWithHostName:@"baidu.com"]; } return _bility; } - (void)dealloc { [[NSNotificationCenter defaultCenter]removeObserver:self name:kReachabilityChangedNotification object:nil]; [self.bility stopNotifier]; NSLog(@"dealloc"); } @end
相关文章推荐
- 网络:下载操作管理器
- 网络:封装下载方法
- 网络:IB 使用技巧
- 网络:下载进度条
- 网络:断点续传
- 网络:取消下载
- 网络:使用多线程下载文件
- [转]使用web.config中的httpHandlers
- 网络:NSOutputStream的使用
- 网络:NSFIleHandle的使用
- 网络:HEAD 的使用
- 网络:文件下载
- javaHTTP请求工具类-使用HttpURLConnection实现
- HttpClient Get/Post方式调用Http接口
- linux 网络编程基础(一)(tcp)
- ios htttp网络请求cookie的读取与写入(NSHTTPCookieStorage)
- LVS在大规模网络环境中的应用
- REST实战——调用百度语音的云服务
- 转自和煦的点滴 » HTML Meta中添加X-UA-Compatible和IE=Edge,chrome=1有什么作用? http://blog.hexu.org/archives/1944.shtm
- TCP/IP的三次握手与四次挥手详解