ios - AFNetworking 未实现

标签 ios iphone objective-c ipad afnetworking-2

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;
 }

当使用这个方法时,成功和失败 block 永远不会被调用。在我将这一行放入实现之后:

[self.operationQueue addOperation:operation];

它有效。为什么 AFNetworking 2.0 AFHTTPRequestOperationManager 错过这一行或者我只是不明白这个方法?谢谢。

最佳答案

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

[self.operationQueue addOperation:operation];

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

关于ios - AFNetworking 未实现,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21488551/

相关文章:

ios - 列出 Podfile 中特定依赖项使用的所有依赖项

ios - Table View 的数据源对象实例保存在哪里比较好?

iphone - 在 iPhone App 中创建倒数计时器

ios - 调用drawrect时xcode报告 "libsystem_kernel.dylib __abort_with_payload"SIGABRT

iphone - 带有自定义单元格的 TableView

ios - 避免触发 touchesBegan : until a swipe gesture recognizer fails

ios - 如何为按钮设置动画以显示右侧 View 并在点击时弹回

iphone - 如何在 Google 日历 API v3 中获取特定日期的日历数据?

objective-c - API 的 CoreData 模型对象

objective-c - 未知类型名称 'ESTBeaconRegion' ;您的意思是 'CLBeaconRegion' 吗?