Thursday, May 20, 2010

Save File in app Folder

http://www.iphonedevsdk.com/forum/iphone-sdk-development/47813-save-image-app-folder.html


- (void)saveImage:(UIImage *)image withName:(NSString *)name {
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSData *data = UIImageJPEGRepresentation(image, 1.0);
NSFileManager *fileManager = [NSFileManager defaultManager];
NSString *fullPath = [documentsDirectory stringByAppendingPathComponent:name];
if(![fileManager createFileAtPath:fullPath contents:data attributes:nil])
{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Saved Failed." message:@"Saved Failed." delegate:self cancelButtonTitle:nil otherButtonTitles:@"OK", nil];
[alert show];
}
else {
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Saved." message:@"Saved." delegate:self cancelButtonTitle:nil otherButtonTitles:@"OK", nil];
[alert show];
}

}

No comments:

Post a Comment