【代码笔记】判断有无网络
2016-05-04 09:19
507 查看
一,工程图。
二,代码。
RootViewController.h
RootViewController.m
二,代码。
RootViewController.h
#import <UIKit/UIKit.h> @interface RootViewController : UIViewController @end
RootViewController.m
#import "RootViewController.h" //加入头文件 #import "Reachability.h" @interface RootViewController () @end @implementation RootViewController - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil { self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]; if (self) { // Custom initialization } return self; } - (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view. if ([self isConnectionAvailable]) { UIAlertView *alert=[[UIAlertView alloc]initWithTitle:@"提醒" message:@"网络已连接,请您一会儿重新发送" delegate:self cancelButtonTitle:@"取消" otherButtonTitles:@"确定", nil]; [alert show]; }; } #pragma -mark -functions //判断网络是否连接。 -(BOOL) isConnectionAvailable{ BOOL isExistenceNetwork = YES; Reachability *reach = [Reachability reachabilityWithHostName:@"www.apple.com"]; switch ([reach currentReachabilityStatus]) { case NotReachable: isExistenceNetwork = NO; //NSLog(@"notReachable"); break; case ReachableViaWiFi: isExistenceNetwork = YES; //NSLog(@"WIFI"); break; case ReachableViaWWAN: isExistenceNetwork = YES; //NSLog(@"3G"); break; } if (!isExistenceNetwork) { UIAlertView *alert=[[UIAlertView alloc]initWithTitle:@"提醒" message:@"网络未连接,请您一会儿重新发送" delegate:self cancelButtonTitle:@"取消" otherButtonTitles:@"确定", nil]; [alert show]; } return isExistenceNetwork; }
相关文章推荐
- 详解https是如何确保安全的?
- 详解https是如何确保安全的?
- 详解https是如何确保安全的?
- HTML, HTTP,web综合问题
- 网络音乐如何打破IP包围圈?靠硬件顶多缓口气
- 为什么UDP有时比TCP更有优势?
- Retrofit2.0+网络框架HTTP实战
- 您未被授权查看该页HTTP错误401.1未经授权解决
- 【BZOJ1497】【codevs1789】最大获利,网络流之最大权闭合子图
- http笔记
- VMware中三种网络连接的区别
- Error: HttpServlet was not found on the Java
- 初识网络请求框架--OKHttp官方介绍
- 对于安卓开发中HttpURLConnection时的路径格式问题解决方案
- 小米路由器mini--OpenWrt刷机/adhoc网络配置/视频传输测试
- Vmware中OpenWrt15.05的网络连接设置
- 厦门巨游网络科技有限公司(HOTPOWER)承接游戏UI外包
- OpenCV进阶之路:神经网络识别车牌字符
- MATLAB处理神经网络基础练习
- 非对称加密、数字摘要、数字签名、数字证书、SSL、HTTPS及其他