2013-10-07 45 views
4

我在AFNetworking可達性模塊工作時遇到了一些麻煩。我用ReachabilityStatusChangeBlock設置了我的AFHTTPRequestOperationManager,但它永遠不會被調用。AFNetworking 2.0可達性不起作用

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的值。

任何幫助?

UPDATE:

我這裏加我PodFile:

pod 'AFNetworking'    ,'~> 2.0.0' 
pod 'AFNetworking/Reachability' ,'~> 2.0.0' 
+0

你是如何導入AFNetworking的?你在用CocoaPods嗎? –

+0

CocoaPods。我一直在使用AFNetworking正常工作!只是不可用的可達性功能。 – bilby91

+0

你可以展示你如何在你的Podfile中包含AFNetworking嗎? –

回答

25

我需要啓動的可達性監測。

[self.manager.reachabilityManager startMonitoring]; 

我偶然發現它,文件應該在我看來註明。

+0

不錯的發現。儘快接受您自己的答案 –

+3

我在AFNetworking中提出了拉取請求。最後這是一個錯誤。 https://github.com/AFNetworking/AFNetworking/commit/4bae4335c25533b5a11d7c8765b6d8a14​​d24974a – bilby91

+0

非常棒,幹得好! –