1

in my app I'm using the new AFN 3.0 and I have

AFHTTPSessionManager *manager

instead of

AFHTTPRequestOperation *operation

my problem is that before I was able to get some data from RequestOperation as:

NSURL *url = operation.request.URL;

//or

NSNumber statusCode = operation.response.statusCode;

//or

NSData *responseData = operation.responseData;

and how can I get this elements with AFHTTPSessionManager?

thanks

cyclingIsBetter
  • 17,447
  • 50
  • 156
  • 241

1 Answers1

1

in v2 you were getting AFHTTPRequestOperation for the request

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);
}];

But in the v3 you will get 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);
}];

So based on that you can get the details the from the NSURLSessionTask like the currentRequest , response etc

For more changes and details, you can refer to the migration guide of AFNetworking AFNetworking Migration Guide

For NSURLSessionTask Reference : NSURLSessionTask

HardikDG
  • 5,892
  • 2
  • 26
  • 55