1

I'm using NSUrlSession to download the contents of an HTML page (so I can parse it, against my will). My problem is that iOS seems to be caching the page with my app, so that even if I update this page on the server, my app keeps seeing the old version (this persists until I delete and reinstall the app).

How can I get NSUrlSession to always download a fresh copy?

Edit: not that complicated, just had to change this:

NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url]

to this:

NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url 
    cachePolicy:NSURLRequestReloadIgnoringLocalAndRemoteCacheData 
    timeoutInterval:0]; 
MusiGenesis
  • 74,184
  • 40
  • 190
  • 334

1 Answers1

1

Try to set your NSURLSessionConfiguration's requestCachePolicy to NSURLRequestReloadIgnoringLocalCacheData.

NSURLSessionConfiguration *configuration = [NSURLSessionConfiguration defaultSessionConfiguration];
configuration.requestCachePolicy = NSURLRequestReloadIgnoringLocalCacheData;
NSURLSession *session = [NSURLSession sessionWithConfiguration:configuration];
graver
  • 15,183
  • 4
  • 46
  • 62