1>AFN网络状态监控:
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
AFNetworkReachabilityManager *mgr = [AFNetworkReachabilityManager sharedManager];
[mgr setReachabilityStatusChangeBlock:^(AFNetworkReachabilityStatus status) {
// 当网络状态发生改变的时候调用这个block
switch (status) {
case AFNetworkReachabilityStatusReachableViaWiFi:
NSLog(@"WIFI");
break;
case AFNetworkReachabilityStatusReachableViaWWAN:
NSLog(@"自带网络");
break;
case AFNetworkReachabilityStatusNotReachable:
NSLog(@"没有网络");
break;
case AFNetworkReachabilityStatusUnknown:
NSLog(@"未知网络");
break;
default:
break;
}
}];
// 开始监控
[mgr startMonitoring];
//主动获得网络状态
mgr.isReachable;
mgr.isReachableViaWiFi;
mgr.isReachableViaWWAN;
}
98 AFNetworking网络状态监控
最新推荐文章于 2024-08-11 19:11:11 发布