网络编程练习 -- 检测网络状态
2014-07-02 17:41
204 查看
LWTViewController.m
View Code
// // LWTViewController.m // 网络编程练习 -- 检测网络状态 // // Created by apple on 14-7-2. // Copyright (c) 2014年 lwt. All rights reserved. // #import "LWTViewController.h" #import "Reachability.h" @interface LWTViewController () @property (nonatomic, strong) Reachability *wann; @end @implementation LWTViewController - (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view, typically from a nib. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(networkStateChange) name:kReachabilityChangedNotification object:nil]; self.wann = [Reachability reachabilityForInternetConnection]; [self.wann startNotifier]; } - (void)dealloc { [self.wann stopNotifier]; [[NSNotificationCenter defaultCenter] removeObserver:self]; } - (void)networkStateChange { // 1.检测wifi状态 Reachability *wifi = [Reachability reachabilityForLocalWiFi]; // 2.检测手机是否能上网络(WIFI\3G\2.5G) Reachability *wann = [Reachability reachabilityForInternetConnection]; // 3.判断网络状态 if (wifi.currentReachabilityStatus != NotReachable) { NSLog(@"有wifi"); }else if([wann currentReachabilityStatus] != NotReachable) { NSLog(@"使用手机自带网络进行上网"); }else { NSLog(@"没有网络"); } } - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { // 1.检测wifi状态 Reachability *wifi = [Reachability reachabilityForLocalWiFi]; // 2.检测手机是否能上网络(WIFI\3G\2.5G) Reachability *wann = [Reachability reachabilityForInternetConnection]; // 3.判断网络状态 if (wifi.currentReachabilityStatus != NotReachable) { NSLog(@"有wifi"); }else if([wann currentReachabilityStatus] != NotReachable) { NSLog(@"使用手机自带网络进行上网"); }else { NSLog(@"没有网络"); } } @end
View Code
相关文章推荐
- Android网络编程实践之旅(三):网络状态检测(续)
- C#编程:网络连接状态的定时检测
- Android网络编程实践之旅(一):网络状态检测
- linux 网络编程之TIME_WAIT状态
- 检测网络状态
- 如何去检测网络的连接状态
- 如何检测Internet联网状态、类型及拨号网络调用?
- [原创]Coding4Fun检测你的网络,用C#获取本机TCP、UDP状态及连接(一)
- 实时检测网络状态及是否可以连接Internet
- 检测网络状态
- 实时检测网络状态及是否可以连接Internet
- 网络编程中的超时检测
- 网络编程的练习2
- 基于Visual C#2010 与WPF开发Windows 7检测网络连接于状态
- Iphone检测网络状态
- 用c/c++实现linux下检测网络接口状态
- 网络状态检测
- 利用PHP脚本检测骨干网络线路状态
- 如何去检测网络的连接状态(C#)
- 网络编程中的超时检测