title: AFNetworking 2: How to cancel a AFHTTPRequestOperationManager request?
body: <p>I migrated my networking functionality from <code>AFNetworking</code> to <code>AFNetworking v2</code> and instead of <code>AFHttpClient</code> I am using <code>AFHTTPRequestOperationManager</code> to support iOS6 as well.</p>
  
  <p>My issue is that while in <code>AFHttpClient</code> there was the functionality to cancel a pending request using the</p>
  
  <pre><code>- (void)cancelAllHTTPOperationsWithMethod:(NSString *)method path:(NSString *)path;
  </code></pre>
  
  <p>method, in the <code>AFHTTPRequestOperationManager</code> there is no such obvious method.</p>
  
  <p>What I've done up to now is subclassing <code>AFHTTPRequestOperationManager</code> and declaring  an iVar</p>
  
  <pre><code>AFHTTPRequestOperation *_currentRequest;
  </code></pre>
  
  <p>When I make a request the code is something like</p>
  
  <pre><code>- (void)GetSomething:(NSInteger)ID success:(void (^)(MyResponse *))success failure:(void (^)(NSError *))failure
  {
      _currentRequest = [self GET:@"api/something" parameters:@{@"ID": [NSNumber numberWithInteger:ID]} success:^(AFHTTPRequestOperation *operation, id responseObject) {
          MyResponse *response = [MyResponse responseFromDictionary:responseObject];
          success(response);
      } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
          failure(error);
  
      }];
  }
  </code></pre>
  
  <p>and I have a </p>
  
  <pre><code>- (void)cancelCurrentRequest;
  </code></pre>
  
  <p>methods which all that does is</p>
  
  <pre><code>- (void)cancelCurrentRequest
  {
      if(_currentRequest) {
          [_currentRequest cancel]; _currentRequest = nil;
      }
  }
  </code></pre>
  
  <p>Now, I don't think this is good practice and when the method is called I get  <code>(NSURLErrorDomain error -999.)</code> which is why I need some advice on getting this done correctly.</p>
  
  <p>Thank you in advance.</p>