Created
April 11, 2014 16:03
-
-
Save joshdholtz/10480351 to your computer and use it in GitHub Desktop.
AFNetworking 2.0 - cancelAllHTTPOperationsWithMethod for AFHTTPRequestOperationManager
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| - (void)cancelAllHTTPOperationsWithMethod:(NSString*)method path:(NSString*)path parameters:(NSDictionary*)parameters ignoreParams:(BOOL)ignoreParams { | |
| NSMutableURLRequest *request = [self.requestSerializer requestWithMethod:(method ?: @"GET") URLString:[[NSURL URLWithString:path relativeToURL:self.baseURL] absoluteString] parameters:parameters]; | |
| NSString *URLStringToMatched = [[request URL] absoluteString]; | |
| for (NSOperation *operation in [self.operationQueue operations]) { | |
| if (![operation isKindOfClass:[AFHTTPRequestOperation class]]) { | |
| continue; | |
| } | |
| NSURL *matchymatchyURL = [[(AFHTTPRequestOperation *)operation request] URL]; | |
| if (ignoreParams == YES) { | |
| NSURLComponents *components = [[NSURLComponents alloc] initWithURL:matchymatchyURL resolvingAgainstBaseURL:YES]; | |
| components.query = nil; | |
| components.fragment = nil; | |
| matchymatchyURL = [components URL]; | |
| } | |
| BOOL hasMatchingMethod = !method || [method isEqualToString:[[(AFHTTPRequestOperation *)operation request] HTTPMethod]]; | |
| BOOL hasMatchingURL = [[matchymatchyURL absoluteString] isEqualToString:URLStringToMatched]; | |
| if (hasMatchingMethod && hasMatchingURL) { | |
| [operation cancel]; | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment