Reachability 网络连接
来源:互联网 发布:管家婆数据库搬移工具 编辑:程序博客网 时间:2024/04/25 09:07
Reachability.h
#import <Foundation/Foundation.h>
#import <SystemConfiguration/SystemConfiguration.h>
#import <netinet/in.h>
所以如果我们在项目中需要用到此类的话,需要引入SystemConfiguration.framework。此类在ios网络开发中可以确认判断网络环境,连接情况(无网络连接,3G,WIFI,GPRS)
enum {
kNotReachable = 0,
kReachableViaWWAN,
kReachableViaWiFi
};
定义三种网络类型:
一:kNotReachable 无网络连接
二:kReachableViaWWAN 使用GPRS或者3G网络连接
三:kReachableViaWiFi 使用WIFI连接
在项目中我们可以用下面的语句判断是否存在网络连接BOOL reachable = [[ReachabilityreachabilityForInternetConnection] isReachable];
if (!reachable) {
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"请检查您的网络连接状态" message:nil delegate:nil cancelButtonTitle:@"确定" otherButtonTitles:nil];
[alertView show];
return;
}
当有网络请求的时候,类中方法可以返回目前的网络连接状态例如:Reachable *reachable = [Reachable reachabilityWithHostName:@"http://write.blog.csdn.net/postedit"];
// These are the status tests.
- (NetworkStatus) currentReachabilityStatus; 返回网络连接状态
/* [reachable currentReachabilityStatus ]包含三个值*/
switch( [reachable currentReachabilityStatus ] ) {
case 0: break;
case 1: break;
case 2: break;
default:
}
- Reachability 检测网络连接
- 关于Reachability网络连接
- Reachability 网络连接
- Reachability 检测网络连接
- Reachability(判断网络是否连接)
- Reachability(判断网络是否连接)
- Reachability(判断网络是否连接)
- Reachability-检测网络是否连接
- Reachability的网络连接的设置
- Reachability实时检测网络连接状况
- IOS 判断网络连接状态 Reachability
- iOS之 网络连接监测框架 Reachability
- 使用Reachability实时检测网络连接
- IOS使用Reachability实时检测网络连接状况
- IOS使用Reachability实时检测网络连接状况
- IOS使用Reachability实时检测网络连接状况
- IOS使用Reachability实时检测网络连接状况
- IOS使用Reachability实时检测网络连接状况
- 第九周 结果预测六
- 编写递归函数求出N的阶乘
- git服务器配置
- CoreData使用笔记 之 增删改查
- 思科telnet配置
- Reachability 网络连接
- android L arm64 kernel image压缩、解压
- MFC获取系统的进程及列表控件使用
- Java学习(十)基本数据类型的包装类
- C++调用C# COM组件
- IP路由选择过程
- 接管微信平台验证
- 第十二周 项目3:(1)编写递归函数求n的阶乘
- 简单的裸机makefile工程