Objective c AFNetworking代码从1.3迁移到2.0

Objective c AFNetworking代码从1.3迁移到2.0,objective-c,afnetworking,afnetworking-2,titanium-modules,Objective C,Afnetworking,Afnetworking 2,Titanium Modules,我是IOS开发的新手。我正试图用AF2.0重写这段代码。如何使用response获取成功或失败回调上的状态代码和标题?这是一个用于AFN网络的钛模块 AFJSONRequestOperation * operation = [AFJSONRequestOperation JSONRequestOperationWithRequest: request success: ^ (NSURLRequest * request, NSHTT

我是IOS开发的新手。我正试图用AF2.0重写这段代码。如何使用response获取成功或失败回调上的状态代码和标题?这是一个用于AFN网络的钛模块

               AFJSONRequestOperation * operation = 
       [AFJSONRequestOperation JSONRequestOperationWithRequest: request 
        success: ^ (NSURLRequest * request, NSHTTPURLResponse * response, id JSON) {
             if (success) {
                 id response_body = JSON;
                 id status_code = [NSNull null];
                 id response_headers = [NSNull null];
                 id reason = [NSNull null];

                 if (!response_body)
                     response_body = [NSNull null];

                 if (response) {
                     status_code = [NSNumber numberWithInteger: response.statusCode];
                     response_headers = response.allHeaderFields;
                 }

                 [self _fireEventToListener: @"complete"
                     withObject: NSDictionaryOfVariableBindings(response_body, status_code, response_headers, reason) 
                     listener: success thisObject: nil
                 ];
                 [UIApplication sharedApplication].networkActivityIndicatorVisible = NO;

             }
         }
         failure: ^ (NSURLRequest * request, NSHTTPURLResponse * response, NSError * error, id JSON) {
             if (failed) {
                 id response_body = JSON;
                 id status_code = [NSNull null];
                 id response_headers = [NSNull null];
                 id reason = [NSNull null];

                 if (!response_body)
                     response_body = [NSNull null];

                 if (response) {
                     status_code = [NSNumber numberWithInteger: response.statusCode];
                     response_headers = response.allHeaderFields;
                 }

                 if (error && error.localizedDescription) {
                     reason = error.localizedDescription;
                 }

                 [self _fireEventToListener: @"complete"
                     withObject: NSDictionaryOfVariableBindings(response_body, status_code, response_headers, reason) 
                     listener: failed thisObject: nil
                 ];
                 [UIApplication sharedApplication].networkActivityIndicatorVisible = NO;
             }
         }
     ];

简单浏览一下代码,您似乎有点误解了块语法

success
块的顶部有
if(success){
code.
在您的代码中,没有一个
success
变量的声明。传递到该success块的唯一变量是
请求、响应、JSON

故障
块中也会发生同样的情况


如果您对这些进行分类,您应该会看到一些进展。

上面的代码目前正在使用afnetworking 1.3版本。这些成功和失败的变量定义为kroll回调。这不在上面的代码中。我找不到使用AFHTTPRequestOperation编写相同代码的方法,因为AFJSONRequestOperation在afnetwo中不可用rking 2.0.AFJSONRequestOperation只允许操作和id作为参数。我需要响应来读取状态代码和标题。@MulticolorPixel