UIImagePickerControllerを使用して写真を撮った後、MessageUIフレームワークを使用して電子メールで画像を送信しています。写真を撮ってメール メッセージ インターフェイスを呼び出すと、作成ウィンドウが表示されます。iPod touch (iOS 4.3.5) および iPad (iOS 5.0.1) でテストすると、作成ウィンドウの本文に画像が添付されているのが見えます。iPhone (4S iOS 5.0.1) でテストすると、画像は作成ウィンドウに表示されませんが、画像の添付ファイルのサイズのボックスが表示され、「?」が埋め込まれた小さな青いボックスが表示されます。初期化。
どちらの場合も、メール メッセージが送信されると、メール アプリ (iOS デバイスと Mac) で受信したメッセージに画像が表示されます。
これを修正するにはどうすればよいですか?
更新:私は変更することでこれを回避しました:
NSData *imageData = [NSData dataWithData:UIImagePNGRepresentation(imageToSend)]
に:
NSData *imageDataJPG = [NSData dataWithData:UIImageJPEGRepresentation(imageToSend, 1.0)];
UIKit ドキュメントで、UIImagePNGRepresentation に iPhone では動作しないものがあることを確認できません ...
(Xcode 4.2.1、ARC、5.0 SDK、デプロイ ターゲット 4.3)
メッセージを作成するためのコードは次のとおりです。
-(void)displayComposerSheet
{
MFMailComposeViewController *mailPicker = [[MFMailComposeViewController alloc] init];
mailPicker.mailComposeDelegate = self;
[mailPicker setSubject:@"Photo"];
NSData *imageData = [NSData dataWithData:UIImagePNGRepresentation(imageToSend)];
[mailPicker addAttachmentData:imageData mimeType:@"image/png" fileName:@"Photo"];
// Fill out the email body text.
NSString *line1 = [NSString stringWithFormat: @"I took this photo on my %@.\n", [[UIDevice currentDevice] model]];
NSString *body = [NSString stringWithFormat:@"%@", line1];
[mailPicker setMessageBody:body isHTML:NO];
// Present the mail composition interface.
[self presentModalViewController:mailPicker animated:YES];
}