0

I understand that AFNetworking has a function that caches an image as it is loaded to an ImageView.

However, I want to cache the Image without displaying it in an ImageView and I was unable to find any functions for that.

Wraithseeker
  • 1,884
  • 2
  • 19
  • 34
  • [See this thread](http://stackoverflow.com/questions/11236401/pre-cache-images-for-afnetworkings-uiimageview-category) – Lefteris May 27 '15 at 08:28

2 Answers2

0

Use [NSBundle mainBundle] resourcePath] to get cache path then use NSFileManager and write file/object/doc etc.

Vicky
  • 602
  • 5
  • 16
0

Something like (Objective C not Swift - but you get the idea)

AFHTTPRequestOperation *requestOperation = [[AFHTTPRequestOperation alloc] initWithRequest:urlRequest];

requestOperation.responseSerializer = [AFImageResponseSerializer serializer];

[requestOperation setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operation, id responseObject) {

    [self savePNGImage:responseObject withFilename:imageUrl];

} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
    NSLog(@"%@", [error description]);
}];
[requestOperation start];

Implement savePNGImage to save your image locally.

CharlesA
  • 4,260
  • 2
  • 25
  • 31