3

メールに画像を添付して、メールアドレスにメールを送信しようとしています。問題は、4つまたは5つの画像が添付されたメールを送信すると、アプリが永久に処理を続け、最終的にハングしてクラッシュし、メールを送信しないことです。1つの画像で正常に動作しています。合わせた画像の大きさのせいだと思います。ところで、私は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

あなたのコードに何か問題があります。私には理解できませんが、このプロジェクトを使用できます。

マルチアタッチファイルで動作し、すべてのケースを処理します。

- (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 に答える
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 に答える