我正在为我的项目将AFNetworking库从1.x迁移到3.x.
根据我的理解,AFHTTPRequestOperation
将替换为AFHTTPSessionManager
。
cancel
类中存在的方法isCancelled
和属性isReady
,request
,response
和AFHTTPRequestOperation
的替代品是什么。< / p>
帮助表示赞赏。
答案 0 :(得分:1)
在 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);
}];