-1

我想使用此代码为我的应用程序将多张照片附加到一封邮件我只能将最后一张照片附加到邮件但我可以在 uiimageview 中阅读所有照片如何将所有照片附加到一封邮件?这是读取图像的代码

- (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)];


    }

第 2 部分去邮件

-(IBAction)actionEmailComposer
{

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

应用程序崩溃了

4

1 回答 1

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.

于 2013-03-09T23:18:43.350 回答