I have several series of images stored in folders on a web server. The folder hierarchy looks something like this…
WebServer’s Web Folder
_20160123161915_4671579
Final
t1.jpg
t2.jpg
i1.jpg
i2.jpg
Recall
t1.jpg
t2.jpg
i1.jpg
i2.jpg
Initial
t1.jpg
t2.jpg
i1.jpg
i2.jpg
The user selects one of the series, initial, Recall, or Final from a list on the iPad and the series is retrieved from the server and displayed. I am using the following code to retrieve the images. In this example I am retrieving the the jpgs that start with a t…
for (int i = 0; i < imageCount; i++) {
fileName = [NSString stringWithFormat:@"t%i.jpg", i+1];
imagePath = [NSString stringWithFormat:@"_%@/%@/%@", [opHelper ID], [seriesArray objectAtIndex:thumbsSeriesIndex], fileName];
urlString = [[NSString stringWithFormat:@"http://%@/%@", [opHelper hostIP], imagePath] stringByAddingPercentEscapesUsingEncoding:NSASCIIStringEncoding];
url = [NSURL URLWithString:urlString];
imageURL = [NSMutableURLRequest requestWithURL:url];
NSURLResponse *response;
NSError *error;
imageData = [NSURLConnection sendSynchronousRequest:imageURL returningResponse:&response error:&error];
//consume the imageData
}
This works except for once in a while I get back blank images for one of the series. In my example, I would get good images with Initial and Recall, but Final comes back with blanks. A 500kb file is requested and imageData gets 800 bytes. I can watch the server hit count increase for each image request. If a series fails the server does not get hit at all. ie. If in the above example file hierarchy I select Recall the server count increases by 4, same with Initial, but if I select Final the server count does not increment.
Here are the actual NSURLs being sent…
url NSURL * @"http://192.168.1.100/_20160123161915_4671579/Final/t1.jpg" 0x80a7f640
url NSURL * @"http://192.168.1.100/_20160123161915_4671579/Recall%201/t1.jpg" 0x804fbcf0
url NSURL * @"http://192.168.1.100/_20160123161915_4671579/Initial/t1.jpg" 0x8088da30
The url for Final in this case was acting up and not hitting the server, but I don’t see anything that jumps out at me in the URLs that might be suspect. Does anyone see anything in my code that might be contributing to this problem? I know it is not a file issue as even if I rename one of the working folders so that the requested file cannot be found, the server gets hit and the iPad receives blank images without any errors.
Thanks for any help.
John
Ok. It was a cache issue. I fixed it by modifying the cache policy...
imageURL = [NSMutableURLRequest requestWithURL:url];
imageURL.cachePolicy = NSURLRequestReloadIgnoringCacheData;
John