IOS Reachability库监听网络状态
来源:互联网 发布:软件产业基地1栋 编辑:程序博客网 时间:2024/05/21 22:25
首先需要导入Reachability.h ...m 2个文件,然后在init注册监听
#import "Reachability.h"
//注册网络状态改变通知 [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(reachabilityChanged:) name:kReachabilityChangedNotification object:nil]; hostReach = [[Reachability reachabilityWithHostName:@"www.baidu.com"] retain];//可以以多种形式初始化 [hostReach startNotifier]; //开始监听,会启动一个run loop
-(void)reachabilityChanged:(NSNotification *)note{ NetworkStatus status = [hostReach currentReachabilityStatus]; if (status == NotReachable){ NSLog(@"网络不可用哦"); isNetworkAvalible = NO; }else{ NSLog(@"网络可用了哦"); isNetworkAvalible = YES; [self startMonitor]; }}<br xmlns="http://www.w3.org/1999/xhtml" />这样就可以动态监测程序内的网络变化了。
这样就可以动态监测程序内的网络变化了。
相关请看:
http://stackoverflow.com/questions/27310465/detecting-network-connectivity-changes-using-reachability-nsnotification-and-ne
http://stackoverflow.com/questions/11177066/how-to-use-ios-reachability
0 0
- IOS Reachability库监听网络状态
- iOS使用Reachability监听网络状态
- ios-通过Reachability监听网络状态
- ios检测网络状态Reachability
- iOS Reachability检测网络状态
- Reachability实时准确监听网络状态
- iOS - 检测网络状态: Reachability和非Reachability
- IOS 判断网络连接状态 Reachability
- iOS 使用Reachability检测网络状态
- iOS 监测网络状态(Reachability)
- iOS 网络状态监测。Reachability 使用
- iOS开发实时监测网络状态Reachability
- http网络编程实例(利用 Reachability监听网络状态)
- 使用苹果自带的Reachability监听网络状态
- 监听网络变化Reachability
- Reachability网络监听
- ios网络状态监听
- ios-监听网络状态
- read-only file system的解决
- keepalived安装与配置
- Sql通用增删改查带参数方法
- NetSpeed--网速检测
- sql和t-sql语句学习
- IOS Reachability库监听网络状态
- V$SQL,V$SQLAREA,V$SQLTEXT
- ios xmpp 文件传输
- unity 给物体边缘加高光轮廓的办法,付Demo(增加一组算法)
- How can I recover a file that I deleted in my local repo from the remote repo in Git?
- sgu-249 Matrix
- wpf 的拖拽功能实现(含拖拽复制功能实现)
- Rename files and folders with git
- XCode5添加新建类模板(Cocos2dx Template Class for Scene or Layer)