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 是用户类(用户定义类)的对象,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 回答