MFMailComposeViewController:附加照片(多张照片)

时间:2013-03-09 16:13:13

标签: ios attachment email-attachments mfmailcomposeviewcontroller mfmailcomposer

我希望将多张照片附加到我的应用程序的一封邮件中 使用此代码,我只能将最后一张照片附加到邮件,但我可以阅读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];
}

该应用已崩溃

1 个答案:

答案 0 :(得分:2)

你有很多关于获取图像和处理与问题无关的用户界面的代码(很可能是你的应用程序崩溃的原因 - 看起来不像是因为你的崩溃了MFMailComposeViewController交互)。如果没有更大的用户界面,您很难获得如何获取图像。

但要专注于您的核心问题:如何将多张照片附加到一封电子邮件中?

答案:多次致电[mailControler addAttachmentData: mimeType: fileName:。如果您不发送两个具有相同文件名的项目,您可以根据需要多次调用它。