如何在Mail Composer中附加图像?

时间:2010-07-17 07:26:24

标签: iphone email

我想使用Mail Composer,它也应附加图像文件,这怎么可能?

2 个答案:

答案 0 :(得分:15)

您可以测试此代码,它完全正常工作......

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

    mailController.mailComposeDelegate = self;

    [mailController setSubject:@"Hello iPhone"];

    [mailController setMessageBody:@"This is the MailSend Application...." isHTML:NO];

    UIImage *pic = [UIImage imageNamed:@"Image box with border-1.png"];
    NSData *exportData = UIImageJPEGRepresentation(pic ,1.0);
    [mailController addAttachmentData:exportData mimeType:@"image/jpeg" fileName:@"Picture.jpeg"];


    [self presentModalViewController:mailController animated:YES];
    [mailController release];
}

- (void)mailComposeController:(MFMailComposeViewController*)mailController 

didFinishWithResult:(MFMailComposeResult)result error:(NSError*)error 

{

        [self becomeFirstResponder];

    [self dismissModalViewControllerAnimated:YES];

}

有关详细信息,请参阅此处的代码检查

http://iosrider.wordpress.com/2012/01/06/how-to-add-email-and-message-in-your-native-application/

答案 1 :(得分:2)

可以附加图像,其他答案提供的测试代码应该有效,但作为第二个来源,位于此网址Mail Pic的Apress的相同代码应该可以帮助您提供一个有效的示例。下载文件夹并打开项目文件的MailPic文件夹。