In my application, I am loading JSON data using the NSURLConnection
method, what looks like this:
NSURLRequest *request = [[NSURLRequest alloc] initWithURL:
[NSURL URLWithString:@"theurl"]];
NSURLConnection *theConnection = [[NSURLConnection alloc] initWithRequest:request
delegate:self];
[theConnection start];
I receive and save the data in the -didReceiveData:
method, but if I update my JSON file on my server, the NSURLConnection
still delivers me the old JSON, while the file is uploaded correctly to the server. Only if I delete the whole app from my iPhone (or iPhone Simulator) and rebuild the application, it receives the new Json file.
Does anyone know a solution for this problem?
You'll need to tell the NSURLRequest to re-evaluate (if your server sends the appropriate modified headers) or not use it's cache. Here's a snippet from my JBAsyncImageView project (hint: Use NSURLRequestReloadRevalidatingCacheData
or NSURLRequestReloadIgnoringLocalCacheData
):
// Create request
self.imageRequest = [[NSURLRequest alloc] initWithURL:imageURL
cachePolicy:(self.cachesImage) ? NSURLRequestReturnCacheDataElseLoad : NSURLRequestReloadIgnoringLocalCacheData
timeoutInterval:self.downloadTimeoutInterval];
// Begin download
self.imageData = nil;
self.imageConnection = [[NSURLConnection alloc] initWithRequest:self.imageRequest
delegate:self
startImmediately:YES];
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With