I am making a small app where the user can create a game profile, input some data and a picture that can be taken with the camera.
I save most of that profile data with
You should save it in Documents
or Cache
folder. Here is how to do it.
Saving into Documents
folder:
NSString* path = [NSHomeDirectory() stringByAppendingString:@"/Documents/myImage.png"];
BOOL ok = [[NSFileManager defaultManager] createFileAtPath:path
contents:nil attributes:nil];
if (!ok)
{
NSLog(@"Error creating file %@", path);
}
else
{
NSFileHandle* myFileHandle = [NSFileHandle fileHandleForWritingAtPath:path];
[myFileHandle writeData:UIImagePNGRepresentation(yourImage)];
[myFileHandle closeFile];
}
Loading from Documents
folder:
NSFileHandle* myFileHandle = [NSFileHandle fileHandleForReadingAtPath:path];
UIImage* loadedImage = [UIImage imageWithData:[myFileHandle readDataToEndOfFile]];
You can also use UIImageJPEGRepresentation
to save your UIImage
as a JPEG
file. What's more if you want to save it in Cache
directory, use:
[NSHomeDirectory() stringByAppendingString:@"/Library/Caches/"]