在我的应用程序中我正在使用新的AFN 3.0而且我有
AFHTTPSessionManager * manager
而不是
AFHTTPRequestOperation *操作
我的问题是,在我能够从RequestOperation获取一些数据之前:
NSURL *url = operation.request.URL;
//or
NSNumber statusCode = operation.response.statusCode;
//or
NSData *responseData = operation.responseData;
如何使用AFHTTPSessionManager获取此元素?
感谢
答案 0 :(得分:1)
在v2中,您获得了AFHTTPRequestOperation
请求
AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
[manager GET:@"http://example.com/resources.json" parameters:nil success:^(AFHTTPRequestOperation *operation, id responseObject) {
NSLog(@"JSON: %@", responseObject);
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
NSLog(@"Error: %@", error);
}];
但是在v3中你会得到NSURLSessionTask
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);
}];
基于此,您可以从NSURLSessionTask
获取详细信息,例如currentRequest
,response
等
有关更多更改和详细信息,请参阅AFNetworking的迁移指南 AFNetworking Migration Guide
对于NSURLSessionTask参考:NSURLSessionTask