0

sqlite データベースから詳細をメールで送信するプログラムを作成しました。

添付ファイルを使用していない場合は正常に機能していますが、コメントを外すと、次のような例外が発生します。

Thread 1: EXC_BAD_ACCESS(code=1, address=0x474e5091

ここに私のコードがあります:

MFMailComposeViewController *mailView = [[MFMailComposeViewController alloc] init];

    mailView.mailComposeDelegate = (id) self;

    NSArray *recipients = [NSArray arrayWithObject:@"chintan_zwt@yahoo.com"];

    [mailView setToRecipients:recipients];
    [mailView setSubject:@"Try Mail From User Application"];

    NSString *body = [[NSString alloc] initWithFormat:@"First Name : %@ <br>",lblFirstName.text];

    body = [body stringByAppendingFormat:@"Last Name : %@<br>",lblLastName.text];
    body = [body stringByAppendingFormat:@"Username  : %@<br>",lblUsername.text];
    body = [body stringByAppendingFormat:@"Password  : %@<br>",lblPassword.text];
    body = [body stringByAppendingFormat:@"Birthdate : %@<br>",lblBD.text];

    [mailView addAttachmentData:[UIImagePNGRepresentation(u.Img1) bytes]
                       mimeType:@"image/png"
                       fileName:@"a.png"];

    [mailView setMessageBody:body isHTML:YES];

    [self presentModalViewController:mailView animated:YES];

データベースからデータを正しく取得しており、画面に画像を表示できますが、問題は画像をメールに添付する場合のみです

ここで

UIImagePNGRepresentation(u.Img1)

U は User Class (ユーザー定義クラス) のオブジェクトで、Img1 は UIImage のオブジェクトです。

4

1 に答える 1

0

addAttachmentData:mimeType:fileName:メソッドの最初にNSDataオブジェクトが必要なため、 で bytes メソッドを呼び出す必要はありませんNSData

コードでこれを試すと、UIImagePNGRepresentation()メソッドが有効な NSData オブジェクトを返すかどうかを確認できます。行にブレークポイントを配置し、デバッガーで値を確認してください。

NSData *imageDate = UIImagePNGRepresentation(u.Img1);
[mailView addAttachmentData:imageDate mimeType:@"image/png" fileName:@"a.png"];
于 2012-09-21T09:43:49.900 に答える