Reputation: 1911
I have been thinking if I should post this question, but I have tried to understand what may be happening and get no idea.
My app downloads some xml files from a server. I have tried it with no internet connection (my router is off, wifi is off) but the simulator keeps getting a 200 http response and showing the data downloaded.
I have logged the response's status code and get 200, and the currentRequest url and the info is correct (the resource's url).
Is there any cache or something where the simulator is getting the data?
The network icon on status bar on simulator is always on.
Upvotes: 1
Views: 176
Reputation: 824
The asy way to fix this is to use the following method of NSMUtableURLRequest
:
[request setCachePolicy:NSURLRequestReloadIgnoringLocalAndRemoteCacheData];
The NSURLRequestReloadIgnoringLocalAndRemoteCacheData
value is the most strict "don't cache anything ever!" option but if you want more specific control, have a look at the docs for the NSURLRequestCachePolicy
enum for all possible options.
Upvotes: 1
Reputation: 12607
You could try this code. It don't cache a data.
NSMutableDictionary* headers = [[[NSMutableDictionary alloc] init] autorelease];
[headers setValue:@"no-cache" forKey:@"Cache-Control"];
[headers setValue:@"no-cache" forKey:@"Pragma"];
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval:TIMEOUT_REQUEST];
[request setHTTPMethod:@"GET"];
[request setAllHTTPHeaderFields:headers];
Upvotes: 2