Image not loading from file path in iOS
ios, iphone, objective-c
Solution
I ran into this problem as well. Hopefully this will save someone a headache down the road.
You can't rely on the Documents Directory to stay consistent from one build to the next. When you re-deploy the app this path could change:
/var/mobile/Applications/2ED5C185-8528-48D3-BE0B-28582DC3D294/Documents/
My problem was I was storing the Document Path in a JSON file and trying to retrieve it on subsequent builds. This piece changes on every build:
2ED5C185-8528-48D3-BE0B-28582DC3D294
Store only the filename with extension and pull the Document Path dynamically. Then you can proceed to prefix the path on the filename.
Problem
I want to load the image from the saved file path of that image that is stored in my iPhone. I am getting the path but still it says file does not exist. This is my code : ``` NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); NSString *documentsDirectory = [paths objectAtIndex:0]; NSString *imagePath = [documentsDirectory stringByAppendingPathComponent:[NSString stringWithFormat:@"%@",self.imageName]]; BOOL fileExists=[[NSFileManager defaultManager] fileExistsAtPath:imagePath]; NSLog(@"%@",imagePath); UIImage *fetchImage = [UIImage imageWithContentsOfFile:imagePath]; ``` fileExists returns NO even when I get this path : /var/mobile/Applications/2ED5C185-8528-48D3-BE0B-28582DC3D294/Documents/IMG_0028.JPG