views:

272

answers:

2

I want to save and read a UIImage to my temp folder when my app closes and then load and delete it when the app loads. How do I accomplish this. Please help.

+1  A: 

These methods allow you to save and retrieve an image from the documents directory on the iphone

+ (void)saveImage:(UIImage *)image withName:(NSString *)name {
        NSData *data = UIImageJPEGRepresentation(image, 1.0);
        NSFileManager *fileManager = [NSFileManager defaultManager];
        NSString *fullPath = [documentsDirectory stringByAppendingPathComponent:name];
        [fileManager createFileAtPath:fullPath contents:data attributes:nil];
    }

    + (UIImage *)loadImage:(NSString *)name {
        NSString *fullPath = [documentsDirectory stringByAppendingPathComponent:name];    
        UIImage *img = [UIImage imageWithContentsOfFile:fullPath];

        return img;
    }
ennuikiller
Thank you for the quick response time. And accurate answer.
Jaba
A: 

In addition, you don't ever want to save anything into the actual tmp directory that you want around after the app shuts down. The tmp directory can be purged by the system. By definition, it exist solely to hold minor files needed only when the app is running.

Files you want to preserve should always go into the documents directory.

TechZen
Thank you I did not know this
Jaba