问题
I'm having some trouble making AFNetworking Reachability module to work. I have setup my AFHTTPRequestOperationManager with a ReachabilityStatusChangeBlock but it's never being called.
self.manager = [[AFHTTPRequestOperationManager alloc] initWithBaseURL:[NSURL URLWithString:@"http://192.168.1.2:3000"]];
self.manager.responseSerializer = [AFJSONResponseSerializer serializer];
NSOperationQueue *operationQueue = self.manager.operationQueue;
[self.manager.reachabilityManager setReachabilityStatusChangeBlock:^(AFNetworkReachabilityStatus status) {
switch (status) {
case AFNetworkReachabilityStatusNotReachable:
// we need to notify a delegete when internet conexion is lost.
// [delegate internetConexionLost];
NSLog(@"No Internet Conexion");
break;
case AFNetworkReachabilityStatusReachableViaWiFi:
NSLog(@"WIFI");
break;
case AFNetworkReachabilityStatusReachableViaWWAN:
NSLog(@"3G");
break;
default:
NSLog(@"Unkown network status");
[operationQueue setSuspended:YES];
break;
}
I have imported SystemConfiguration/SystemConfiguration.h in my .pch as the documentation says. Every time i ask for the status i get the value -1.
Any help?
UPDATE:
I add my PodFile here:
pod 'AFNetworking' ,'~> 2.0.0'
pod 'AFNetworking/Reachability' ,'~> 2.0.0'
回答1:
I needed to start the reachability monitor.
[self.manager.reachabilityManager startMonitoring];
I find it by accident, documentation should state this in my opinion.
来源:https://stackoverflow.com/questions/19232622/afnetworking-2-0-reachability-not-working