AFNetworking accepts all types of content

I am performing a query operation to download all file types from a server using AFHTTPRequestOperationManager.

At the moment, I am doing this:

AFHTTPRequestOperationManager *manager = [[AFHTTPRequestOperationManager alloc] initWithBaseURL:baseURL]; manager.responseSerializer.acceptableContentTypes = [NSSet setWithObjects:@"image/jpeg", @"image/gif", @"image/png", @"application/pdf", ..., nil]; 

It works well, but I would like to include all types of content in order to avoid some.

Is it possible to initiate valid content types for any type of existing content? Sort of:

 manager.responseSerializer.acceptableContentTypes = [NSSet setWithObjects:@"*", nil]; 

Thanks.

+5
source share
2 answers

just set a validContentTypes to nil.

The corresponding code in AFNetworking looks like this:

  if (self.acceptableContentTypes && ![self.acceptableContentTypes containsObject:[response MIMEType]]) { ... 

ifapproContentTypes is zero, then it does not check and just loads.

+4
source

If someone who finds this should add a certain type of MIME image to the list of valid content, you can do the following:

 #import <AFNetworking/UIImageView+AFNetworking.h> #import <AFNetworking/AFImageDownloader.h> AFImageResponseSerializer* serializer = (AFImageResponseSerializer*)[UIImageView sharedImageDownloader].sessionManager.responseSerializer; serializer.acceptableContentTypes = [serializer.acceptableContentTypes setByAddingObject:@"image/jpg"]; 

We needed to support the "image / jpg" MIME image types, and this worked fine.

0
source

Source: https://habr.com/ru/post/1215124/


All Articles