Reputation: 1986
I am working on the webservices based application. In this, on the very first view I am downloading the images and saving it to application path. E.g.
/Users/k.shinde/Library/Application Support/iPhone Simulator/5.0/Applications/6291C790-CFD3-413A-849A-A38ED3368CED/Documents/0.png
Now I want to retrieve the image from the above mentioned image path to display it on table view cell. I have tried alot of methods to implement this. But i didn't get the result. Please give me some idea.
Upvotes: 1
Views: 227
Reputation: 4546
Keep this in mind:
The iOS Data Storage Guidelines specify:
Only documents and other data that is user-generated, or that cannot otherwise be recreated by your application, should be stored in the /Documents directory and will be automatically backed up by iCloud.
Data that can be downloaded again or regenerated should be stored in the /Library/Caches directory. Examples of files you should put in the Caches directory include database cache files and downloadable content, such as that used by magazine, newspaper, and map applications.
Data that is used only temporarily should be stored in the /tmp directory. Although these files are not backed up to iCloud, remember to delete those files when you are done with them so that they do not continue to consume space on the user’s device.
Use the "do not back up" attribute for specifying files that should remain on device, even in low storage situations. Use this attribute with data that can be recreated but needs to persist even in low storage situations for proper functioning of your app or because customers expect it to be available during offline use. This attribute works on marked files regardless of what directory they are in, including the Documents directory. These files will not be purged and will not be included in the user's iCloud or iTunes backup. Because these files do use on-device storage space, your app is responsible for monitoring and purging these files periodically.
So I think you should use NSCachesDirectory
instead of NSDocumentsDirectory
Upvotes: 0
Reputation: 15147
This function will be helpful for you..
- (UIImage*)loadImage:(NSString *)pImageName
{
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *fullPath = [documentsDirectory stringByAppendingPathComponent:pImageName];
return [UIImage imageWithContentsOfFile:fullPath];
}
Happy Coding..
Upvotes: 3