#pragma mark - 监测网络的可链接性
+ (void)netWorkReachabilityWithURLString:(NSString *)strUrl
{
AFHTTPRequestOperationManager *manager = [[AFHTTPRequestOperationManager alloc] initWithBaseURL:[NSURL URLWithString:strUrl]];
[manager.reachabilityManager setReachabilityStatusChangeBlock:^(AFNetworkReachabilityStatus status) {
switch (status) {
case AFNetworkReachabilityStatusUnknown:
case AFNetworkReachabilityStatusNotReachable: {
[[NSNotificationCenter defaultCenter] postNotificationName:DMNetworkInvalidNotification object:nil];
UIAlertView *networkAlterView = [[UIAlertView alloc] initWithTitle:@"当前网络不可用,请检查您的网络设置。"
message:nil
delegate:self
cancelButtonTitle:@"好"
otherButtonTitles:nil, nil];
[networkAlterView show];
}
break;
case AFNetworkReachabilityStatusReachableViaWWAN:
[[NSNotificationCenter defaultCenter] postNotificationName:DMNetworkActiveNotification object:nil];
break;
case AFNetworkReachabilityStatusReachableViaWiFi:
[DMTools HUDError:DMRequestWIFINote toView:DMWindow];
[[NSNotificationCenter defaultCenter] postNotificationName:DMNetworkActiveNotification object:nil];
break;
}
}];
[manager.reachabilityManager startMonitoring];
}
+ (void)netWorkReachabilityWithURLString:(NSString *)strUrl
{
AFHTTPRequestOperationManager *manager = [[AFHTTPRequestOperationManager alloc] initWithBaseURL:[NSURL URLWithString:strUrl]];
[manager.reachabilityManager setReachabilityStatusChangeBlock:^(AFNetworkReachabilityStatus status) {
switch (status) {
case AFNetworkReachabilityStatusUnknown:
case AFNetworkReachabilityStatusNotReachable: {
[[NSNotificationCenter defaultCenter] postNotificationName:DMNetworkInvalidNotification object:nil];
UIAlertView *networkAlterView = [[UIAlertView alloc] initWithTitle:@"当前网络不可用,请检查您的网络设置。"
message:nil
delegate:self
cancelButtonTitle:@"好"
otherButtonTitles:nil, nil];
[networkAlterView show];
}
break;
case AFNetworkReachabilityStatusReachableViaWWAN:
[[NSNotificationCenter defaultCenter] postNotificationName:DMNetworkActiveNotification object:nil];
break;
case AFNetworkReachabilityStatusReachableViaWiFi:
[DMTools HUDError:DMRequestWIFINote toView:DMWindow];
[[NSNotificationCenter defaultCenter] postNotificationName:DMNetworkActiveNotification object:nil];
break;
}
}];
[manager.reachabilityManager startMonitoring];
}