2016-01-19 213 views
1

我正在爲我的項目將AFNetworking庫從1.x遷移到3.x。AFNetworking從1.x遷移到3.x

根據我的理解,AFHTTPRequestOperation被替換爲AFHTTPSessionManager。 什麼是方法cancel和屬性isCancelled,isReady,requestresponse的替代品,它們出現在AFHTTPRequestOperation類中。

幫助讚賞。

回答

0

AFHTTPRequestOperationManager

AFHTTPSessionManager *manager = [AFHTTPSessionManager manager]; 

[manager GET:@"http://example.com/resources.json" parameters:nil progress:nil success:^(NSURLSessionTask *task, id responseObject) { 

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

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

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

AFHTTPRequestOperation

NSURL *URL = [NSURL URLWithString:@"http://example.com/resources/123.json"]; 

AFHTTPSessionManager *manager = [AFHTTPSessionManager manager]; 

[manager GET:URL.absoluteString parameters:nil progress:nil success:^(NSURLSessionTask *task, id responseObject) { 

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

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

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