Believe in your own future, will thank yourself right now Sinner Yun

Sinner_Yun

AFN 无网络监控

 

直接把封装到请求里就好

 

 1 -(void)afn{
 2 //1.创建网络状态监测管理者
 3 AFNetworkReachabilityManager *manger = [AFNetworkReachabilityManager sharedManager];
 4 //开启监听,记得开启,不然不走block
 5 [manger startMonitoring];
 6 //2.监听改变
 7 [manger setReachabilityStatusChangeBlock:^(AFNetworkReachabilityStatus status) {
 8 /*
 9 AFNetworkReachabilityStatusUnknown = -1,
10 AFNetworkReachabilityStatusNotReachable = 0,
11 AFNetworkReachabilityStatusReachableViaWWAN = 1,
12 AFNetworkReachabilityStatusReachableViaWiFi = 2,
13 */
14 switch (status) {
15 case AFNetworkReachabilityStatusUnknown:
16 NSLog(@"未知");
17 break;
18 case AFNetworkReachabilityStatusNotReachable:
19 NSLog(@"没有网络");
20 break;
21 case AFNetworkReachabilityStatusReachableViaWWAN:
22 NSLog(@"3G|4G");
23 break;
24 case AFNetworkReachabilityStatusReachableViaWiFi:
25 NSLog(@"WiFi");
26 break;
27 default:
28 break;
29 }
30 }];
31 }

 

posted on 2016-11-02 15:49  Sinner_Yun  阅读(372)  评论(0编辑  收藏  举报

导航