AppDelegate中的didFinishLaunchingWithOptions中注冊監(jiān)聽
AFNetworkReachabilityManager *mgr = [AFNetworkReachabilityManager sharedManager];
[mgr setReachabilityStatusChangeBlock:^(AFNetworkReachabilityStatus status) {
switch (status) {
case AFNetworkReachabilityStatusUnknown:
break;
case AFNetworkReachabilityStatusNotReachable:
break;
case AFNetworkReachabilityStatusReachableViaWiFi:
break;
case AFNetworkReachabilityStatusReachableViaWWAN:
break;
default:
break;
}
}];
[mgr startMonitoring];
在界面中
AFNetworkReachabilityManager *mgr = [AFNetworkReachabilityManager sharedManager];
NSLog(@"%d", mgr.isReachable);