iphone - 将多个图像附加到电子邮件

标签 iphone ios image email attachment

我正在使用 ELCimagepicker 将多个图像附加到电子邮件中,但我不确定如何使每个 NSData 都是唯一的,以便我可以将它们附加到我的电子邮件中。

>

- (void)launchController {
  ELCAlbumPickerController *albumController = [[ELCAlbumPickerController alloc] initWithNibName:@"ELCAlbumPickerController" bundle:[NSBundle mainBundle]];
  ELCImagePickerController *elcPicker = [[ELCImagePickerController alloc] initWithRootViewController:albumController];
  [albumController setParent:elcPicker];
  [elcPicker setDelegate:self];
  [self presentModalViewController:elcPicker animated:YES];
 }

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

  [self dismissModalViewControllerAnimated:YES];
  int i = 0;
  for(NSDictionary *dict in info) {
     i++;
     UIImageView *imageview = [[UIImageView alloc] initWithImage:[dict     objectForKey:UIImagePickerControllerOriginalImage]];
     NSData *name = UIImageJPEGRepresentation(imageview, 1.0);
   }

}

最佳答案

从此链接获取应用程序 https://github.com/elc/ELCImagePickerController

以及代码的后续更改

使用for循环

-(IBAction)launchController 

{

ELCAlbumPickerController *albumController = [[ELCAlbumPickerController alloc] initWithNibName:@"ELCAlbumPickerController" bundle:[NSBundle mainBundle]];    
ELCImagePickerController *elcPicker = [[ELCImagePickerController alloc] initWithRootViewController:albumController];
[albumController setParent:elcPicker];
[elcPicker setDelegate:self];

ELCImagePickerDemoAppDelegate *app = (ELCImagePickerDemoAppDelegate *)[[UIApplication sharedApplication] delegate];
[app.viewController presentModalViewController:elcPicker animated:YES];
[elcPicker release];
[albumController release];

[self buttonPressed];

}



- (void)buttonPressed
{
    // Create image picker controller
    UIImagePickerController *imagePicker = [[UIImagePickerController alloc] init];

    // Set source to the camera
    imagePicker.sourceType =  UIImagePickerControllerSourceTypeSavedPhotosAlbum;

    // Delegate is self
    imagePicker.delegate = self;

    // Allow editing of image ?
    imagePicker.allowsImageEditing = NO;

    // Show image picker
    [self presentModalViewController:imagePicker animated:YES]; 
}







- (void)emailImage:(UIImage *)image
{
    MFMailComposeViewController *picker = [[MFMailComposeViewController alloc] init];
    picker.mailComposeDelegate = self;

    // Set the subject of email
    [picker setSubject:@"Picture from my iPhone!"];

    // Add email addresses
    // Notice three sections: "to" "cc" and "bcc"   
    [picker setToRecipients:[NSArray arrayWithObjects:@"emailaddress1@domainName.com", @"emailaddress2@domainName.com", nil]];
    [picker setCcRecipients:[NSArray arrayWithObject:@"emailaddress3@domainName.com"]]; 
    [picker setBccRecipients:[NSArray arrayWithObject:@"emailaddress4@domainName.com"]];

    // Fill out the email body text
    NSString *emailBody = @"I just took this picture, check it out.";


    for (int i=0; i<[imagedelegate.imgarray count]; i++) 
    {

        UIImageView *image=[[UIImageView alloc] init];
        image=[imagedelegate.imgarray objectAtIndex:i];

    // This is not an HTML formatted email
    [picker setMessageBody:emailBody isHTML:NO];

    // Create NSData object as PNG image data from camera image
    NSData *data = UIImagePNGRepresentation(image);

    // Attach image data to the email
    // 'CameraImage.png' is the file name that will be attached to the email
    [picker addAttachmentData:data mimeType:@"image/png" fileName:@"CameraImage"];

    // Show email view  
    [self presentModalViewController:picker animated:YES];

    // Release picker
    [picker release];
    }
}



- (void) imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
    // Access the uncropped image from info dictionary
    UIImage *image = [info objectForKey:@"UIImagePickerControllerOriginalImage"];

    // Dismiss the camera
    [self dismissModalViewControllerAnimated:YES];

    // Pass the image from camera to method that will email the same
    // A delay is needed so camera view can be dismissed
    [self performSelector:@selector(emailImage:) withObject:image afterDelay:1.0];

    // Release picker
    [picker release];
}

关于iphone - 将多个图像附加到电子邮件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12047448/

相关文章:

ios - 在 Custom Cocoapods 中使用 Storyboards 和 Image assets

ios - 如何在左侧导航栏项目上添加圆形图像

c++ - 从 HSV 直方图中获取主色值

java - Android 项目中图像的最大宽度是多少? ( Sprite 相关问题)

iphone - 我的服务器如何安全地验证 iPhone 应用内购买?

iphone - 通用应用程序适用于 iPad 1,但不适用于 iPad 2

ios - 制作圆形动画的正确方法是什么?

iphone - UIPickerView在iOS4中导致崩溃

iphone - 如何以编程方式将应用程序带到前台

android - 大图像导致应用程序崩溃