How to check if have a new version of the image is

2019-08-17 04:30发布

问题:

I have some images that is stored in my WebServer.

So I want that always that the user opens the app or refresh, it check if have a new version of the image available and if yes, download it?

I have tried https://github.com/Julioacarrettoni/iOS-ImageManager, but it doesn't work, it keeps reloading the view all the time.

Thanks,

回答1:

There are a couple of ways for the app to know if the image has been updated on the server:

  1. Guess that it might change once a week and not worry about the redownloads when it doesn't change and the delay before redownload when it does.
  2. Check when it was last modified on the server and download when the modified date it newer than your copy of the data.

Option 1 uses the http cache policy information. Options 2 uses the http last modified header information. Both options rely on the server providing the appropriate headers in the response so the client can decide whether to continue or abort the request.

The poor mans alternative is to just ignore the server specified cache and only try to download the image once per week, using a local copy of the image in between times.

Docs for the headers: here. How they are implemented depends on the construction of your server.

You might also want to look at SDWebImage