title: How to timeout or detect slow response in AFHTTPSessionManager in AFNetworking?
body: <p>With my code below, the failure block fires immediately if there is no internet connection - and that is good. But what if there is a connection, but no internet?</p>
  
  <p>I've read this question: <a href="https://stackoverflow.com/questions/8304560/how-to-set-a-timeout-with-afnetworking">How to set a timeout with AFNetworking</a> which suggests to use the reachabilityManager and the example in this answer shows the use - <a href="https://stackoverflow.com/questions/21938680/afnetworking-2-0-queue-request-when-device-is-offline-with-setreachabilitystatus">AFNetworking 2.0 queue request when device is offline with setReachabilityStatusChangeBlock does nothing</a>.</p>
  
  <p>BUT, if my simulator or phone is connected to my wifi network but does not have internet access (DNS, DHCP, or modem issues), my code at present continues to try to reach my API for a long time. I'm not downloading anything and I know my script and my server should respond in seconds so I know that after 5 seconds of inactivity, something is wrong.</p>
  
  <p>So can I safely do a timeout, or can I use the reachabilityManager in my current script to detect if the script (not the internet) is not reachable and if so, how?</p>
  
  <pre><code>- (void)APICall:(NSMutableDictionary*)params {
  
      NSURL *baseURL = [NSURL URLWithString:BaseURLString];
      NSDictionary *parametersGetAuthCode = @{@"req": @"getauth"};
  
      AFHTTPSessionManager *manager = [[AFHTTPSessionManager alloc] initWithBaseURL:baseURL];
  
      manager.responseSerializer = [AFJSONResponseSerializer serializer];
      [manager POST:APIscript parameters:parametersGetAuthCode success:^(NSURLSessionDataTask *task, id responseObject) {
          if ([task.response isKindOfClass:[NSHTTPURLResponse class]]) {
              NSHTTPURLResponse *r = (NSHTTPURLResponse *)task.response;
              if ([r statusCode] == 200) {
  
              //do success stuff
  
              }
          }
      } failure:^(NSURLSessionDataTask *task, NSError *error) {
          UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Error" message:[error localizedDescription] delegate:nil cancelButtonTitle:@"Ok" otherButtonTitles:nil];
          [alertView show];
  
          //do failure stuff
  
      }];
  
  }
  </code></pre>