0

I want to display an image on UIImageView calling the Web server image. Because I want to replace and show it right away.

here's the code

NSURL *imageURL = [NSURL URLWithString:urlString];
NSData *imageData = [NSData dataWithContentsOfURL:imageURL];
webImage.image = [UIImage imageWithData:imageData];

The problem is... The image is displayed well at first, but if I replaced the image on the web server with another image.(The file name is the same, only the file is replaced) It didn't change and still displayed the first image.

Please help me...

The Dreams Wind
  • 8,416
  • 2
  • 19
  • 49
devSimba
  • 11
  • 1
  • Are you using NSURLSession? Check your cachePolicy. See more [here](https://stackoverflow.com/questions/21957378/how-to-cache-using-nsurlsession-and-nsurlcache-not-working). – griv Sep 03 '22 at 03:13

1 Answers1

0

The code in the question seems flawed, i.e. you apparently do a network request in the UI thread. Such approach tends to make your application UI unresponsive. However, if we boil down the question to "Why NSData returns outdated data for the same URL?" then the answer is because it has internal caching. The caching logic could controlled either by the the response headers from the server (e.g. Expires) or with NSDataReadingUncached option (to suppress any caching logic):

NSData *data = [NSData dataWithContentsOfURL:url options:NSDataReadingUncached error:nil];
The Dreams Wind
  • 8,416
  • 2
  • 19
  • 49