【问题标题】:Attaching a image to an email in an app in ipad in ios6在 iOS6 中的 ipad 中的应用程序中将图像附加到电子邮件中
【发布时间】:2012-10-29 13:18:20
【问题描述】:

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

【问题讨论】:

  • 同一个应用在 ios5 中运行良好....
  • 那么,如果你将图片数量减少到 2 张,它在 iOS 6 中可以正常工作吗?如果是这种情况,那么它应该是由于内存警告。为此,您可能必须使用一些压缩或调整大小选项。
  • 2张图片可以.. 3张以后有问题....但是ios5发送5张图片也是可能的...
  • 嗨...任何解决方案?如何更改合并发送的文件的最大大小?

标签: ios ipad email ios5 ios6


【解决方案1】:

我不知道你的代码有问题,但你可以使用this project 它是

使用多附件文件并处理所有情况。

- (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];
}

【讨论】:

  • 发邮件没问题..发带图片的邮件是问题...那你怎么回答是正确的?
  • 我使用了该项目并附加了多张图片,它适用于我,我在上面发布了一个代码来处理每个案例,让你知道你的电子邮件发生了什么。那你有什么问题???
  • 它适用于 ios5.. 在 ios6 中,当我附加超过 3 张图像时,它会挂起并且应用程序根本没有进展......
  • 等一下,我会试试,告诉你我发生了什么。
  • 那你是怎么尝试的?有什么问题吗?
【解决方案2】:

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-05-04
    • 1970-01-01
    • 1970-01-01
    • 2012-03-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多