AFHTTPRequestOperationManager有这个实现:
- (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;
}
使用此方法时,成功和失败块永远不会被调用。我把这一行放在实现中之后:
[self.operationQueue addOperation:operation];
它有效。为什么AFNetworking 2.0 AFHTTPRequestOperationManager错过了这一行,或者我只是不明白这种方法?感谢。
答案 0 :(得分:2)
HTTPRequestOperationWithRequest
创建一个操作,但不执行它。将操作添加到使用此调用创建的操作队列时:
[self.operationQueue addOperation:operation];
您实际上是在执行刚刚创建的操作。然后将调用成功和失败块。