1

我正在为我的项目将 AFNetworking 库从 1.x 迁移到 3.x。

据我了解,AFHTTPRequestOperation要替换为AFHTTPSessionManager. 类中存在的方法和cancel属性isCancelled,isReady和的替代品是什么。requestresponseAFHTTPRequestOperation

帮助表示赞赏。

4

1 回答 1

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);
}];
于 2016-07-26T10:57:10.120 回答