Reputation: 138
I've come across a problem I can't find a solution to. I've searched the forums extensively but can't find anything. Hopefully someone might be able to shed some light.
I have an app that can save images. They are saved to the apps documents directory and the path to them is saved in a sqlite database. Every time I run/build the app, it can no longer retrieve the images that are already in the documents directory. During that same build phase I can re-save the images and then I can retrieve them just fine, but as soon as I run/build the app again it can't retrieve the images. The images are not being deleted and the path is still correct.
This is how I try retrieving them in my ViewDidLoad method
//database was opened. Getting path to image
NSString *logoPath = [[NSString alloc] initWithUTF8String:(const char *) sqlite3_column_text(statement, 21)];
//use path to load image to a UIImage view
[self.logoView setImage:[UIImage imageWithContentsOfFile:logoPath]];
I have confirmed that the image is in the documents directory still and the path is correctly assigned in my first line of code above. This code only fails when I run/build the app. Once the app is running I can save images to the directory and retrieve them with this same code just fine, but once I run/build the app again, the images I saved on the previous build can't be pulled up even though I can see them in the directory still (I use iExplorer to view my iPhones directories).
Any ideas? Im thinking that maybe I have to initiate those images in the directory somehow in order to use them right after I build.
UPDATE - Some more info in case it will help. After the app is built on my iPhone, I can close the app and reopen it and the images work just fine. I can even completely close the app (double click home button and end app process) and when I relaunch the app the images are retrieved from the directory just fine. But as soon as I build the app again through xCode, I cannot access the images. Something is changing when a new build is done.
UPDATE 2 - I think I found the issue and it is in the path. This is my path
/var/mobile/Containers/Data/Application/8A387845-7B1F-4228-9E7E-2498EC302C5A/Documents/RYal7UXrLvcompanyLogo.png
After I build the app again, this is now the new path when I save the image again
/var/mobile/Containers/Data/Application/C0C30E2F-05D8-48F4-A0FF-603359AF5130/Documents/RYal7UXrLvcompanyLogo.png
Looks like the part in between Applications and Documents changes after every build so the path I am saving in my sqlite db is no longer valid after a new build. So now I need to figure out what that middle part is that keeps changing and how to get it after each build so I can update my paths to my images.
Upvotes: 2
Views: 708
Reputation: 138
The issue was the path. Every time a new build was created, part of the path to the documents directory changed. See UPDATE 2 in the original question above.
Upvotes: 1