cyclingIsBetter
cyclingIsBetter

Reputation: 17591

iOS: AFHTTPSession manager response data

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

Upvotes: 1

Views: 323

Answers (1)

HardikDG
HardikDG

Reputation: 6112

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

Upvotes: 1

Related Questions