Images not found on disk between builds


I am playing around with the ImageCache and have found that images are sometimes found and sometimes not found on disk between launches and builds of the application.

For example snapping a photo in “Release” setting and then building in “Debug” have caused images to not be found. But this has been very flakey and not real easy to reproduce or explain in detail. A previously saved image may be loaded repeatedly from disk but sometimes a “new” image is not saved, or not saved in a way that the app can find it later. I have checked that it is not a problem with the image id (or key) not being saved to the plist. It is there and I see the log showing things like:
“Error: unable to find /var/mobile/Applications/7A69C06C-0CB0-4C58-8133-59A0B586E6B5/Documents/78A02F64-8458-4743-A9AF-1365E37F0A15”
(from inside ImageCache)

I was wondering if there was some known “issue” or “housekeeping” done when running the iPhone hooked up to Xcode that may cause the image files to be either removed or not saved to disk. Or is this just some voodoo going on with my phone or code?

btw. The book is excellent. Well written and very well organised and structured. I love it and have tossed my other iphone books (all two of them) in a dark corner. :slight_smile:


I have isolated the “problem” a bit further. Looks like images taken when the app was launched from Xcode do not stick around but that images taken after “re-launching” the app do. Does that make sense? Is that expected behaviour?


Hmm… the images should stick around. When you rebuild an application and deploy to the simulator, sometimes a separate sandbox is created in the directory you are talking about. But, the documents, library and tmp directories should be copied to that new sandbox.


This is also an issue for me. Thanks eimermusic for narrowing down the problem as I was wasting hours trying to identify a bug in the code. I noticed this is a three year old post. Are there any updates or suggestions for this problem? I’m currently working through the iOS 3rd Edition on chapter 14 “Saving, Loading, and Application States.” As eimermusic pointed out, the image will not properly save when launching the app from Xcode, but does save when I use the app straight from the iPhone (iOS 6). The crazy thing is that the app works as expected when using the BNR solution for this chapter. Any thoughts?