UIImageView + AFNetworking does not receive the last image from the server

I am facing a problem in image caching. I can not get a new image. Because I use the same URL to get the image. But on the server side, my administrator changed the images at this URL location.

I know that there is one way to check if it is new or old based on the status code or cache controller.

Here's my question: is there a way to get the URL status code without downloading content?

Step1: The image from the online address was uploaded successfully. using the following method

(void)setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholderImage; This is successfully display on my image view and cached. Step 2: I changed image from server. Url is same. So I can not able to get latest image. I am always getting old image.

Question: How to get the last image from the server using the UIImageView + AFNetworking category with the same URL?

Note. I successfully get the status code from the server (304 or 200). So how can I handle it?

+4
source share
2 answers

Can I try to reset the category cache? but it will delete all objects in the cache so you can decide whether you want all new images to be extracted at all times. Try it,

  [yourImageView setSharedImageCache:nil];

If you want to check the status code and everything you got to work on your own category for UIImageView or break up an existing category, check out this method for more details.

- (void)setImageWithURLRequest:(NSURLRequest *)urlRequest
              placeholderImage:(UIImage *)placeholderImage
                       success:(void (^)(NSURLRequest *request, NSHTTPURLResponse *response, UIImage *image))success
                       failure:(void (^)(NSURLRequest *request, NSHTTPURLResponse *response, NSError *error))failure
+1
source

Try installing cachePolicy using the NSURLRequestfollowing:

[_yourImageView setImageWithURLRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@
    "YOUR URL"] cachePolicy:NSURLRequestReloadIgnoringLocalCacheData timeoutInterval:30.0] placeholderImage:placeholder success:^(NSURLRequest *request, NSHTTPURLResponse *response, UIImage *image) {
            [_yourImageView setImage:image];
        } failure:nil];
+1
source

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


All Articles