Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Download PDF file with AFNetworking 2.0

I want to update to the latest version of AFNetworking. I was wondering how to download a PDF from a server to display it in my app.

On the old version I used this code:

    AFHTTPRequestOperation *operation = [[AFHTTPRequestOperation alloc] initWithRequest:request];
    operation.responseSerializer = [AFHTTPResponseSerializer serializer]; 
    [operation setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operation, id responseObject) {

        [webView loadData:responseObject MIMEType:@"application/pdf" textEncodingName:nil baseURL:nil];
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
//error handling
}

[operation start];

What does the code look like in AFNetworking 2.0 to get the same job done? Do I have to use another class of AFNetworking?

like image 779
halloway4b Avatar asked Nov 02 '13 21:11

halloway4b


1 Answers

Just need to add

operation.responseSerializer = [AFHTTPResponseSerializer serializer];

Now it is working so far. Thanks.

like image 186
halloway4b Avatar answered Oct 01 '22 11:10

halloway4b