Reputation: 625
AFHTTPRequestOperationManager has this implementation:
- (AFHTTPRequestOperation *)HTTPRequestOperationWithRequest:(NSURLRequest *)request
success:(void (^)(AFHTTPRequestOperation *operation, id responseObject))success
failure:(void (^)(AFHTTPRequestOperation *operation, NSError *error))failure
{
AFHTTPRequestOperation *operation = [[AFHTTPRequestOperation alloc] initWithRequest:request];
operation.responseSerializer = self.responseSerializer;
operation.shouldUseCredentialStorage = self.shouldUseCredentialStorage;
operation.credential = self.credential;
operation.securityPolicy = self.securityPolicy;
[operation setCompletionBlockWithSuccess:success failure:failure];
return operation;
}
when use this method, the success and failure blocks never get call. After I put this line in the implementation:
[self.operationQueue addOperation:operation];
it works. Why AFNetworking 2.0 AFHTTPRequestOperationManager miss this line or I just don't understand this method? Thanks.
Upvotes: 3
Views: 112
Reputation: 6597
HTTPRequestOperationWithRequest
creates an operation, but does not execute it. When you add the operation to the operation queue you created with this call:
[self.operationQueue addOperation:operation];
you are essentially executing the operation you just created. Then the success and failure blocks will get called.
Upvotes: 2