I have an iOS project with an Mvx base that has problems loading images.
I have several screens that contain UICollectionViews, and UICollectionViewCells use MvxDynamicImageHelpers to set the image of their UIImageViews to images posted on the Internet (the Azure blob repository via the Azure CDN actually). I noticed that images sometimes donβt appear and that this is more likely to happen when connecting slowly, and if I view the entire UICollectionView while loading images - apparently because it initiates a large number of simultaneous downloads. Restarting the application causes some, but not all, images to be displayed.
In the Cache / Pictures.MvvmCross folder, I see that there are several files with .tmp extensions and some without .tmp extensions, but the file size is 0 bytes. I assume that the .tmp files are those that are reloaded after the application is restarted and that an invalid entry in the in-memory cache does not allow them to be reloaded until this happens.
I implemented my versions of MvxDownloadRequest and MvxHttpFileDownloader and registered my IMvxHttpFileDownloader. The only modification to MvxHttpFileDownloader is to use my MvxDownloadRequest instead of the standard Mvx file.
As far as I can tell, the exceptions in MvxDownloadRequest.Start or MvxDownloadRequest.ProcessResponse and MvxDownloadRequest.FileDownloadFailed are not called. Replacing MvxDownloadRequest.Start as follows, all images always load and display successfully:
try { ThreadPool.QueueUserWorkItem((state) => { try { var fileService = this.GetService<IMvxSimpleFileStoreService>(); var tempFilePath = DownloadPath + ".tmp"; var imageData = NSData.FromUrl(NSUrl.FromString(Url)); var image = UIImage.LoadFromData(imageData); NSError nsError; image.AsPNG().Save(tempFilePath, true, out nsError); fileService.TryMove(tempFilePath, DownloadPath, true); } catch (Exception exception) { FireDownloadFailed(exception); return; } FireDownloadComplete(); }); } catch (Exception e) { FireDownloadFailed(e); }
So, what can cause problems with the standard WebRequest, which does not affect the above version? I guess something with the GC and will continue to debug when I get the time, but, unfortunately, this will not happen yet. It would be very appreciated if someone could answer this or provide pointers when I look at it.
Thanks,
J
source share