iOS学习之--------------使用系统方法检测网络情况
2015-05-28 22:38
686 查看
可以使用系统自带的方法对程序的网络情况进行检测,具体实现代码如下:
@property
(nonatomic,strong)
Reachability * conn
1、创建监听
self.conn = [[NSNotificationCenter
defaultCenter]
addObserver : self
selector
: @selector(check)
name:kReachabilityChangedNotification
object:nil];
self.conn
=[Reachability
reachabilityForInternetConnection];
//开始监控
[self.conn
startNotifier];
- (void)dealloc
{
//结束监控
[self.conn
stopNotifier];
//移除
[[NSNotificationCenter
defaultCenter]removeObserver:self];
}
- (void)check
{
//检测wifi状态
Reachability
*wifi = [Reachability
reachabilityForLocalWiFi];
//检测手机自带的上网功能
Reachability
*conn = [Reachability
reachabilityForInternetConnection];
if
([wifi
currentReachabilityStatus] !=
NotReachable) {
NSLog(@"有wife");
}
else
if
([conn
currentReachabilityStatus]){
NSLog(@"使用手机的3g网络");
}
else
{
NSLog(@"没有网络");
}
}
@property
(nonatomic,strong)
Reachability * conn
1、创建监听
self.conn = [[NSNotificationCenter
defaultCenter]
addObserver : self
selector
: @selector(check)
name:kReachabilityChangedNotification
object:nil];
self.conn
=[Reachability
reachabilityForInternetConnection];
//开始监控
[self.conn
startNotifier];
- (void)dealloc
{
//结束监控
[self.conn
stopNotifier];
//移除
[[NSNotificationCenter
defaultCenter]removeObserver:self];
}
- (void)check
{
//检测wifi状态
Reachability
*wifi = [Reachability
reachabilityForLocalWiFi];
//检测手机自带的上网功能
Reachability
*conn = [Reachability
reachabilityForInternetConnection];
if
([wifi
currentReachabilityStatus] !=
NotReachable) {
NSLog(@"有wife");
}
else
if
([conn
currentReachabilityStatus]){
NSLog(@"使用手机的3g网络");
}
else
{
NSLog(@"没有网络");
}
}
相关文章推荐
- 机器人驾驶的神经网络愿景(下)
- 三层网络结构(核心层 汇聚层 接入层)
- 爬虫其实很简单!——网络爬虫快速实现(一)
- 爬虫其实很简单!——网络爬虫快速实现(一)
- 01.VMware虚拟机上网络连接(network type)的三种模式--bridged、host-only、NAT
- HTTP错误代码
- Java Servlet学习笔记(五)Servlet服务器Http响应
- HTTP协议状态码详解(HTTP Status Code)
- Java Servlet学习笔记(四)Servlet客户端Http请求
- 【编程者必会系列】:TCP/IP之传输层
- cmd创建wifi
- Linux运维之Web基础(HTTP基础)
- 如何计算IP地址的网络号和主机号?
- tcpdump
- 阿里云ecs+主机宝linux版+沃通免费ssl配置https方法
- hash blog http://www.360doc.com/content/13/0409/14/10384031_277138819.shtml
- 网络服务器常见设计
- 实现HTTP协议Get、Post和文件上传功能——设计和模块
- HTTP网络启动安装原版系统ISO镜像
- Socket网络编程--FTP客户端(2)(Windows)