2016-07-25 451 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我更新了.. :) –