4

我在使 AFNetworking 可达性模块工作时遇到了一些麻烦。我已经使用 ReachabilityStatusChangeBlock 设置了我的 AFHTTPRequestOperationManager,但它从未被调用过。

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;
        }

如文档所述,我已在 .pch 中导入了 SystemConfiguration/SystemConfiguration.h。每次我询问状态时,我都会得到值-1。

有什么帮助吗?

更新:

我在这里添加我的 PodFile:

pod 'AFNetworking'              ,'~> 2.0.0'
pod 'AFNetworking/Reachability' ,'~> 2.0.0'
4

1 回答 1

25

我需要启动可达性监视器。

[self.manager.reachabilityManager startMonitoring]; 

我偶然发现它,我认为文档应该说明这一点。

于 2013-10-08T19:07:49.950 回答