2016-07-25 133 views
0

我有以下AFNetworking 2代码(来自库),我尝试迁移到AFNetworking 3,但我无法理解如何执行数据任务而不是NSOperations。任何帮助,将不胜感激:将代码从AFNetworking 2迁移到3

NSURLRequest *request = [self requestWithMethod:@"GET" 
              path:messagePath 
            parameters:nil]; 
AFHTTPRequestOperation *operation = [self HTTPRequestOperationWithRequest:request 
                    success:^(AFHTTPRequestOperation *_operation, id responseObject) { 
                     if (success) { 
                      success(responseObject); 
                     } 
                    } 
                    failure:^(AFHTTPRequestOperation *_operation, NSError *error) { 
                     NSLog(@"%@", error); 
                     if (failure) { 
                      failure(error); 
                     } 
                    }]; 
+0

你有什么想说的? –

+0

请点击此链接。 https://github.com/AFNetworking/AFNetworking/wiki/AFNetworking-3.0-Migration-Guide –

回答

1

不喜欢以下内容:

AFHTTPSessionManager *manager = [AFHTTPSessionManager manager]; 

[manager GET:@"Enter_your_URL_here" parameters:nil progress:nil success:^(NSURLSessionTask *task, id responseObject) { 

    NSLog(@"JSON: %@", responseObject); 

} 
failure:^(NSURLSessionTask *operation, NSError *error) { 

    NSLog(@"Error: %@", error); 
} 
]; 
+0

将'manager.responseSerializer'分配两次看起来不是最优的。 – Droppy

+0

是的,谢谢@ Droppy..now我更新了.. :) –