gpt4 book ai didi

html - 如何在 MFMailComposer 邮件正文中添加图像(不是作为附件)

转载 作者:搜寻专家 更新时间:2023-10-30 19:56:39 24 4
gpt4 key购买 nike

我想在编辑器中添加一个图像,这样当我打开邮件编辑器时,图像应该在邮件正文中。我不要附件。而且我也不想将图像转换为base64。还有其他方法吗???

谢谢。

最佳答案

你好,我使用下面的代码在 iphone 和 ipad 中完美地工作。我有使用此代码的 attacha 图像文件。它的工作代码。

- (void)createEmail {
//Create a string with HTML formatting for the email body
NSMutableString *emailBody = [[[NSMutableString alloc] initWithString:@"<html><body>"] retain];
//Add some text to it however you want
[emailBody appendString:@"<p>Some email body text can go here</p>"];
//Pick an image to insert
//This example would come from the main bundle, but your source can be elsewhere
UIImage *emailImage = [UIImage imageNamed:@"myImageName.png"];
//Convert the image into data
NSData *imageData = [NSData dataWithData:UIImagePNGRepresentation(emailImage)];
//Create a base64 string representation of the data using NSData+Base64
NSString *base64String = [imageData base64EncodedString];
//Add the encoded string to the emailBody string
//Don't forget the "<b>" tags are required, the "<p>" tags are optional
[emailBody appendString:[NSString stringWithFormat:@"<p><b><img src='data:image/png;base64,%@'> </b></p>",base64String]];
//You could repeat here with more text or images, otherwise
//close the HTML formatting
[emailBody appendString:@"</body></html>"];
NSLog(@"%@",emailBody);

//Create the mail composer window
MFMailComposeViewController *emailDialog = [[MFMailComposeViewController alloc] init];
emailDialog.mailComposeDelegate = self;
[emailDialog setSubject:@"My Inline Image Document"];
[emailDialog setMessageBody:emailBody isHTML:YES];

[self presentModalViewController:emailDialog animated:YES];
[emailDialog release];
[emailBody release];
}

关于html - 如何在 MFMailComposer 邮件正文中添加图像(不是作为附件),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8665894/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com