13th,September,2016
获取网络状态
AFNetworkReachabilityManager *reachabilityManager = [AFNetworkReachabilityManager sharedManager];
if (!reachabilityManager.reachable) {
failedResponse(@"网络无法连接"); // 网络出问题了
return;
}
实时监测网络
AFNetworkReachabilityManager *manager = [AFNetworkReachabilityManager sharedManager];
[manager startMonitoring];
[manager setReachabilityStatusChangeBlock:^(AFNetworkReachabilityStatus status) {
switch (status) {
case AFNetworkReachabilityStatusUnknown:
NSLog(@"AFNetworkReachabilityStatusUnknown");
// 发送系统通知,通知无网络
// [operationQueue setSuspended:YES];
break;
case AFNetworkReachabilityStatusNotReachable:
NSLog(@"AFNetworkReachabilityStatusNotReachable");
// [operationQueue setSuspended:YES];
break;
case AFNetworkReachabilityStatusReachableViaWWAN:
NSLog(@"AFNetworkReachabilityStatusReachableViaWWAN");
// 通知有网络
// [operationQueue setSuspended:NO];
break;
case AFNetworkReachabilityStatusReachableViaWiFi:
NSLog(@"AFNetworkReachabilityStatusReachableViaWiFi");
// [operationQueue setSuspended:NO];
break;
default:
break;
}
}];
未完待续,敬请期待…
ps: 万事开头难,一定要坚持开头,然后可以再完善