将图像附加到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;rntx-unix-mode=0644;rntname="%@"",strFileName];
                NSString *strFormat2 = [NSString stringWithFormat:@"attachment;rntfilename="%@"",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;rntx-unix-mode=0644;rntname="%@"",strFileName];
                NSString *strFormat2 = [NSString stringWithFormat:@"attachment;rntfilename="%@"",strFileName];
                NSDictionary *vcfPart = [NSDictionary dictionaryWithObjectsAndKeys:strFormat,kSKPSMTPPartContentTypeKey,
                                         strFormat2,kSKPSMTPPartContentDispositionKey,[imageData encodeBase64ForData],kSKPSMTPPartMessageKey,@"base64",kSKPSMTPPartContentTransferEncodingKey,nil];
                [parts addObject:vcfPart];
            }
        }

似乎IOS6限制了图像的大小...因此,最好压缩图像...

最新更新