3

我正在尝试将图像附加到电子邮件并将电子邮件发送到我的电子邮件地址。问题是,当我发送一封附有 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];
            }
4

2 回答 2

0

只需将其从 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限制了图片的大小……所以还是压缩图片比较好……

于 2012-12-30T11:35:07.360 回答
0

你的代码有问题我不知道,但你可以使用这个项目

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

- (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];
}
于 2012-11-13T10:04:31.557 回答