Okay, I'm really not sure what is going on here and I've been stuck on this for several of days.
My app stored images in the cloud on AWS. As you scroll through say an activity feed, it will fetch images in the background and save them in a cached location so that it's not constantly fetching images. The cache is essentially a circular array so that I cache at most 100 images. That all works fine.
The code to save the image (they're always jpgs) follows the example almost line by line: http://docs.xamarin.com/recipes/ios/network/web_requests/download_an_image/
In a WebClient_DownloadCompleted call back, I save the file:
void WebClient_DownloadCompleted(object sender, DownloadDataCompletedEventArgs e)
{
// Save the results in the cached file.
bool success = (e.Error == null && e.Result != null);
if (success)
ImageCache.SetImageFile(e.UserState.ToString(), e.Result); // <-- this is a service that I have
}
In my service call, I am literally just doing
File.WriteAllBytes(path, bytes);
after the housekeeping with the circular array. That's just a mapping from requested URL to local path. Again, that is all working. Here's what I don't understand: when I have the file in the cache, and I call to load the image:
// Ask my service if we have it cached.
if (ImageCache.IsImageFileAvailable(_imageUrl))
{
// It is cached locally, just load from the file.
SamplePhoto.Image = UIImage.FromFile(ImageCache.GetImageFilePath(_imageUrl));
}
This ALWAYS works on my iPhone.
This ALWAYS fails on some iPhones (not mine).
I have confirmed that the file is there and that the file is an image like I expected. What happens is that FromFile is returning null. I'm at a loss because I can't determine what is different between my iPhone and the others. Why would this fail? How can I debug it further? We're both using the exact same builds.
Help!
JB