AFN检测网络

2017-05-25  本文已影响0人  c42b9af86268

/**

监测网络的可链接性

@param strUrl URL地址

@return 是否可达

*/

+(BOOL)netWorkReachabilityWithURLString:(NSString *) strUrl {

__block BOOL netState = YES;

[[AFNetworkReachabilityManager sharedManager] setReachabilityStatusChangeBlock:^(AFNetworkReachabilityStatus status) {

switch (status) {

case AFNetworkReachabilityStatusNotReachable:

case AFNetworkReachabilityStatusUnknown:

netState = NO;

break;

case AFNetworkReachabilityStatusReachableViaWiFi:

case AFNetworkReachabilityStatusReachableViaWWAN:

netState = YES;

break;

default:

break;

}

NSLog(@"Reachability: %@", AFStringFromNetworkReachabilityStatus(status));

}];

[[AFNetworkReachabilityManager sharedManager] startMonitoring];

return netState;

}

上一篇下一篇

猜你喜欢

热点阅读