-1

i want attach multi photos to one mail for my application with this code i can attach only the last one photos to mail but i can read all photos in uiimageview how can attaching all photos to one mail ? here is the codes for read image

- (void)elcImagePickerController:(ELCImagePickerController *)picker didFinishPickingMediaWithInfo:(NSArray *)info {

 [self dismissModalViewControllerAnimated:YES];

 ////
    if ([MFMailComposeViewController canSendMail]) {





        MFMailComposeViewController * mailControler = [[MFMailComposeViewController alloc]init];
        mailControler.mailComposeDelegate = self;
        mailControler.modalPresentationStyle = UIModalPresentationFormSheet;



        NSString *emailBody = @"";  // optional
        [mailControler setMessageBody:emailBody isHTML:YES];



    for (UIView *v in [scrollview subviews]) {
        [v removeFromSuperview];
    }

 CGRect workingFrame = scrollview.frame;
 workingFrame.origin.x = 0;

 for(NSDictionary *dict in info) {

  imageview = [[UIImageView alloc] initWithImage:[dict objectForKey:UIImagePickerControllerOriginalImage]];

        [imageview setContentMode:UIViewContentModeScaleAspectFit];
  imageview.frame = workingFrame;

  [scrollview addSubview:imageview];
  [imageview release];

  workingFrame.origin.x = workingFrame.origin.x + workingFrame.size.width;
        NSLog(@"image %@", imageview.image);



        NSData * data = UIImageJPEGRepresentation(imageview.image, 0.0);

 [mailControler addAttachmentData:data mimeType:@"image/jpeg" fileName:@"Photos"];


 }





    [scrollview setPagingEnabled:YES];
    [scrollview setContentSize:CGSizeMake(workingFrame.origin.x, workingFrame.size.height)];


    }

Part 2 go mail

-(IBAction)actionEmailComposer
{

  [self presentViewController:mailControler animated:YES completion:nil];
}

the app is crashed

1 Answers1

2

You've got a whole mess of code in there about obtaining your images and dealing with your UI that is irrelevant to the question (and quite possibly why your app is crashing -- doesn't look like it's crashing because of your MFMailComposeViewController interaction). How you're obtaining your images is very hard to follow without the context of your larger UI.

But to focus on just your core question: how do you attach multiple photos to one email?

Answer: call [mailControler addAttachmentData: mimeType: fileName: multiple times. You can call it as many times as you need, provided you don't send two items with the same filename.

Bill Patterson
  • 2,495
  • 1
  • 19
  • 20
  • Which is to say: if your app is crashing, it's either something about unrelated code, or because you keep sending "photos" as the filename on every single call. Docs specifically say you can't reuse filenames. – Bill Patterson Mar 09 '13 at 23:20