【问题标题】:AFNetworking miss implemetationAFNetworking 未实施
【发布时间】:2014-01-31 19:36:15
【问题描述】:

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 错过了这一行,或者我只是不明白这个方法?谢谢。

【问题讨论】:

    标签: ios iphone objective-c ipad afnetworking-2


    【解决方案1】:

    HTTPRequestOperationWithRequest 创建一个操作,但不执行它。当您将操作添加到您使用此调用创建的操作队列中时:

    [self.operationQueue addOperation:operation];
    

    您实际上是在执行您刚刚创建的操作。然后调用成功和失败块。

    【讨论】:

    • 另外,如果 OP 不需要使用操作队列,[operation start] 也可以。
    猜你喜欢
    • 1970-01-01
    • 2015-10-13
    • 2022-01-27
    • 2023-02-09
    • 1970-01-01
    • 2021-02-06
    • 2016-12-14
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多