ios - Offline mode using NSURLCache -


I am using AFURLetworking with NSURLCache. The request is made with NSURLRequestUseProtocolCachePolicy . Receives response with app headers:

  etag = "13 9 8684731"; Cache-control = "public";  

And everything works perfect. But now I need to add offline mode.

How it should work:

  • Everything should work normally if the internet connection is available (application asks back-end for new data and if It is different in etag if etag is similar - if cached response is used then new data is downloaded).
  • If there is no internet connection - the cached response is used.

The problem is that offline mode requests fail.

I have tried to solve this by using different cache-control options but it seems that it does not work like this.

I have found possible solutions here It should work but it is not very elegant and I think there may be some change in the past year.

Apart from this, I've found that "NSURLCache was not designed for clear offline scenarios and it was designed to speed up Safari and should not be used for manual download". Will SDURLCache be better for my purposes?

So what could be the best way to implement offline mode?

It seems that you want a request to succeed, even if the cache says that the data ends Has been done and should be recovered from the server. You may have a set of cash policies (separate policy for online vs offline) for certain requests, which you do not use even if you fail to use the data.

Great Link Is Here ->


Comments

Popular posts from this blog

import - Python ImportError: No module named wmi -

Editing Python Class in Shell and SQLAlchemy -

c# - MySQL Parameterized Select Query joining tables issue -