I’m using this piece of code to try and save an image to the documents directory:
//FOR TESTING ON SIMULATOR
UIImage* image = [UIImage imageNamed:@"ReceiptImage1.jpg"];
NSData *imageData = UIImagePNGRepresentation(image);
NSString* imageName = @"Receipt1Image1.png";
NSArray* paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString* documentsDirectory = [paths objectAtIndex:0];
NSString* fullPathToFile = [documentsDirectory stringByAppendingPathComponent:imageName];
[imageData writeToFile:fullPathToFile atomically:NO];
self.receiptImage1 = fullPathToFile;
self.receiptImageView1.image = [UIImage imageWithContentsOfFile:fullPathToFile];
NSLog(@"fullPathToFile %@", fullPathToFile);
However this piece of code doesn’t set the imageViews image to the receipt image that I’m trying to write to the documents directory.
Can someone explain what I’m doing wrong and how to fix it?
Thanks,
Jack
Use this: