在ios6中的ipad中将图像附加到应用程序中的电子邮件中

我正在尝试将图像附加到电子邮件中并将电子邮件发送到我的电子邮件添加。 问题是,当我发送附有4或5个图像的电子邮件时,该应用程序将继续处理并最终被绞死和崩溃,并且不会发送电子邮件。 一张图片工作正常。 我认为这是因为图像的大小组合在一起。 顺便说一下,我正在使用iOS 6 ..我如何限制发送的文件或图像的大小? 或者可能涉及其他问题? 相同的应用程序正在ios5 ….

电子邮件发送部分与图像一起是:

for (int nCtr = 0; nCtr < [Pix count]; nCtr++) { UIImageView *imageV = [Pix objectAtIndex:nCtr]; if (imageV.image) { NSData *imageData = UIImagePNGRepresentation(imageV.image); NSString *strFileName = [NSString stringWithFormat:@"MyPicture-%d.jpeg",nCtr]; NSString *strFormat = [NSString stringWithFormat:@"image/jpeg;\r\n\tx-unix-mode=0644;\r\n\tname=\"%@\"",strFileName]; NSString *strFormat2 = [NSString stringWithFormat:@"attachment;\r\n\tfilename=\"%@\"",strFileName]; NSDictionary *vcfPart = [NSDictionary dictionaryWithObjectsAndKeys:strFormat,kSKPSMTPPartContentTypeKey, strFormat2,kSKPSMTPPartContentDispositionKey,[imageData encodeBase64ForData],kSKPSMTPPartMessageKey,@"base64",kSKPSMTPPartContentTransferEncodingKey,nil]; [images addObject:vcfPart]; } 

您的代码中有一些错误我无法想象,但您可以使用此项目

工作将与多附件文件,它处理所有情况。

 - (void)mailComposeController:(MFMailComposeViewController*)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError*)error { switch (result) { case MFMailComposeResultCancelled: NSLog(@"Mail cancelled: you cancelled the operation and no email message was queued."); break; case MFMailComposeResultSaved: NSLog(@"Mail saved: you saved the email message in the drafts folder."); break; case MFMailComposeResultSent: NSLog(@"Mail send: the email message is queued in the outbox. It is ready to send."); break; case MFMailComposeResultFailed: NSLog(@"Mail failed: the email message was not saved or queued, possibly due to an error."); break; default: NSLog(@"Mail not sent."); break; } // Remove the mail view [self dismissModalViewControllerAnimated:YES]; } 

只需将其从PNG格式更改为JPEG格式即可。

 for (int nCtr = 0; nCtr < [arrPix count]; nCtr++) { UIImageView *imageV = [arrPix objectAtIndex:nCtr]; if (imageV.image) { NSData *imageData = UIImageJPEGRepresentation(imageV.image, 0.9); NSString *strFileName = [NSString stringWithFormat:@"MyPicture-%d.jpeg",nCtr]; NSString *strFormat = [NSString stringWithFormat:@"image/jpeg;\r\n\tx-unix-mode=0644;\r\n\tname=\"%@\"",strFileName]; NSString *strFormat2 = [NSString stringWithFormat:@"attachment;\r\n\tfilename=\"%@\"",strFileName]; NSDictionary *vcfPart = [NSDictionary dictionaryWithObjectsAndKeys:strFormat,kSKPSMTPPartContentTypeKey, strFormat2,kSKPSMTPPartContentDispositionKey,[imageData encodeBase64ForData],kSKPSMTPPartMessageKey,@"base64",kSKPSMTPPartContentTransferEncodingKey,nil]; [parts addObject:vcfPart]; } } 

似乎ios6限制了图像的大小...因此压缩图像效果更好......