标签:网络监测
#import"AFNetworking.h"
#import"TSMessage.h"
在监测网络的地方
//检查网络状态
[selfcheckNetworkStatus];
#pragmamark网络状态监测
-(void)checkNetworkStatus{
//tsmessage
//[TSMessagesetDefaultViewController:self.view];
//创建一个用于测试的url
NSURL*url=[NSURLURLWithString:@"http://www.apple.com"];
AFHTTPRequestOperationManager*operationManager=[[AFHTTPRequestOperationManageralloc]initWithBaseURL:url];
//根据不同的网络状态改变去做相应处理
[operationManager.reachabilityManagersetReachabilityStatusChangeBlock:^(AFNetworkReachabilityStatusstatus){
switch(status){
caseAFNetworkReachabilityStatusReachableViaWWAN:
[TSMessageshowNotificationWithTitle:@"2G/3G/4G连接."type:TSMessageNotificationTypeWarning];
break;
caseAFNetworkReachabilityStatusReachableViaWiFi:
[TSMessageshowNotificationWithTitle:@"WiFi连接."type:TSMessageNotificationTypeSuccess];
break;
caseAFNetworkReachabilityStatusNotReachable:
[TSMessageshowNotificationWithTitle:@"断网了...,请检查你的网络是否连接!"type:TSMessageNotificationTypeError];
break;
}
}];
//开始监控
[operationManager.reachabilityManagerstartMonitoring];
}
效果图如下:
标签:网络监测
原文地址:http://blog.csdn.net/huanghaiyan_123/article/details/45443539