//网络监测
[SVProgressHUD setDefaultMaskType:SVProgressHUDMaskTypeNone];
//厚度
[SVProgressHUD setRingThickness:6];
//1.获得网络监控的管理者
AFNetworkReachabilityManager *manager = [AFNetworkReachabilityManager sharedManager];
//2.设置网络状态改变后的处理
[manager setReachabilityStatusChangeBlock:^(AFNetworkReachabilityStatus status) {
//当网络状态改变后,会调用这个方法
switch (status) {
case AFNetworkReachabilityStatusUnknown:{
UIAlertView *alert1 = [[UIAlertView alloc] initWithTitle:@"温馨提示" message:@"请检查您当前的网路" delegate:self cancelButtonTitle:@"确定" otherButtonTitles:nil, nil];
[alert1 show];
[alert1 release];
}
break;
case AFNetworkReachabilityStatusNotReachable:
{
UIAlertView *alert2 = [[UIAlertView alloc] initWithTitle:@"温馨提示" message:@"好痛苦!断网了!" delegate:self cancelButtonTitle:@"确定" otherButtonTitles:nil, nil];
[alert2 show];
[alert2 release];
}
break;
case AFNetworkReachabilityStatusReachableViaWWAN:
{
[SVProgressHUD showSuccessWithStatus:@"3G/4G网络"];
[[NSNotificationCenter defaultCenter] postNotificationName:@"reload" object:nil];
}
break;
case AFNetworkReachabilityStatusReachableViaWiFi:
{
[SVProgressHUD showSuccessWithStatus:@"WIFI"];
[[NSNotificationCenter defaultCenter] postNotificationName:@"reload" object:nil];
}
break;
default:
break;
}
}];
//3 开始监测
[manager startMonitoring];