Reputation: 9660
I have a .gif image which is only accessible if I am on Wifi. On a certain domain like mydomain.mysite.com/myimage.gif the image is not accessible.
But on my production environment the image some how becomes accessible and returns the following response:
<NSHTTPURLResponse: 0x156c5200> { URL: } { status code: 200, headers {
"Accept-Ranges" = bytes;
"Cache-Control" = "max-age=86400";
"Content-Length" = 554;
"Content-Type" = "image/gif";
Date = "Wed, 26 Mar 2014 14:47:53 GMT";
Etag = "\"030329e4e9c91:11c4\"";
"Last-Modified" = "Tue, 09 Jun 2009 13:17:20 GMT";
Server = "Microsoft-IIS/6.0";
"X-Powered-By" = "ASP.NET";
} }
My Objective C code is as follows:
NSHTTPURLResponse *response;
NSError *error = nil;
NSURL *url = [NSURL URLWithString:currentEnvironment];
NSURLRequest *request = [NSURLRequest requestWithURL:url];
[NSURLConnection sendSynchronousRequest:request returningResponse:&response
error:&error];
if(response != nil) return YES;
return NO;
SOLUTION:
I believe this is the solution: The cachePolicy is implemented.
NSURL *url = [NSURL URLWithString:currentEnvironment];
NSURLRequest *request = [NSURLRequest requestWithURL:url cachePolicy:NSURLRequestReloadIgnoringCacheData timeoutInterval:60.0];
[NSURLConnection sendSynchronousRequest:request returningResponse:&response
error:&error];
Upvotes: 0
Views: 46
Reputation: 9660
The production server was sending the Cache-Control headers which was caching the response. The solution is to specify NSURLRequest to not cache which is implemented below:
NSURL *url = [NSURL URLWithString:currentEnvironment];
NSURLRequest *request = [NSURLRequest requestWithURL:url cachePolicy:NSURLRequestReloadIgnoringCacheData timeoutInterval:60.0];
[NSURLConnection sendSynchronousRequest:request returningResponse:&response
error:&error];
Upvotes: 1