简体   繁体   中英

How to upload images from gallery to a supporting files in iOS?

I am a newbie to iOS and I have given a task of creating a small app, which allows user to select image from the gallery and selected image gets displayed in the UIImage view and should get saved in images folder under supporting files.

Currently image gets saved under documents folder, using following block of code:

NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
localFilePath = [documentsDirectory stringByAppendingPathComponent:@"savedImage.png"];
self.imageView.image = image;
[picker dismissModalViewControllerAnimated:YES];

How can I save selected image under image folder in supporting files?

Following is the folder structure in my project

The image can be able to save in the phone memory not in the images folder what you have, If you want to save the image with in your project you can able to save through core data or sqlite database but you cannot see the image in your images folder.

Am not sure why you need to show that on the images folder but its not possible i think according to my knowledge.

Based on your requirement which is given by you on comment I have edited my previous answer.

   MFMailComposeViewController *mail = [[MFMailComposeViewController alloc] init];
   mail.mailComposeDelegate = self;
   [mail setSubject:@"find attachment"];
   UIImage *selectedImage = "put your image from your image view/ selected gallery image"
   NSData *myData = UIImagePNGRepresentation(selectedImage);
   [mail addAttachmentData:myData mimeType:@"image/png" fileName:@"coolImage.png"];

   // set email body
   NSString *emailBody = @"My cool image is attached";
   [mail setMessageBody:emailBody isHTML:NO];
   [self presentModalViewController:mail animated:YES];

All the best

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM