IOS开发——网络监测
来源:互联网 发布:拳师七号淘宝店 编辑:程序博客网 时间:2024/06/05 10:28
网络监测
工具下载地址:http://download.csdn.net/detail/u012881779/7020685
编译文件不支持ARC,需要引入支持工具的框架:SystemConfiguration.framework。
interface部分:
#import "Reachability.h"//网络监测@property (strong, nonatomic)Reachability *ymNetwork;
implementation部分:
-(void)viewDidLoad{ [super viewDidLoad]; [self.view setBackgroundColor:[UIColor grayColor]]; //设置通知,网络改变时触发 [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(changeNetwork:) name:kReachabilityChangedNotification object:nil]; //创建Reachability对象 self.ymNetwork = [Reachability reachabilityForInternetConnection]; //开始监听网络 [self.ymNetwork startNotifier]; //获得当前网络 NetworkStatus status = [self.ymNetwork currentReachabilityStatus]; [self checkNetwork:status];}#pragma mark - 网络检测//判断当前是什么网络-(void)checkNetwork:(NetworkStatus)status{ //没有网的时候进行提示 if (status==kNotReachable) { [self messageBox:@"没有网络"]; }else if (status==kReachableViaWWAN){ [self messageBox:@"正在使用2G/3G网络"]; }else if (status==kReachableViaWiFi){ [self messageBox:@"正在使用wifi网络"]; }}-(void)messageBox:(NSString*)string{ UIAlertView *alert=[[UIAlertView alloc] initWithTitle:@"提示"message:string delegate:nil cancelButtonTitle:@"确定"otherButtonTitles:nil,nil]; [alert show];}//网络改变时调用-(void)changeNetwork:(NSNotification*)notification{ //获得当前网络 NetworkStatus status=[self.ymNetwork currentReachabilityStatus]; [self checkNetwork:status]; }
0 0
- IOS开发——网络监测
- iOS开发网络篇—监测网络状态
- iOS开发网络篇—监测网络状态
- iOS开发网络篇—监测网络状态
- iOS开发网络篇—监测网络状态
- iOS开发网络—10监测网络状态
- iOS开发网络篇—监测网络状态
- iOS开发网络篇—监测网络状态
- iOS开发网络篇—监测网络状态
- iOS开发网络篇—监测网络状态
- iOS开发网络篇—监测网络状态
- iOS开发网络篇—监测网络状态
- iOS开发网络篇—监测网络状态
- iOS开发网络篇—监测网络状态
- iOS开发网络篇—监测网络状态
- iOS开发网络篇—监测网络状态
- iOS开发:网络监测
- iOS ——网络监测
- session application
- 【洛洛】縢薇聪是不是美妞
- ZStack OSAL的事件(event)与消息(message)——part1 & part2
- 类模板
- hadoop伪分布式操作方法
- IOS开发——网络监测
- 使用bosh—cli在vsphere上部署micro bosh
- Java主线程等待子线程、线程池
- java 第六天 面向对象(基础篇之static)
- Jaxb annotation初步使用
- JavaScript正则比较两个字符串
- 静态方法不能被子类覆盖
- CSipSimple 简单分析
- 第2周:Java事件处理