我想在作曲家中添加圖像,以便當我打開郵件編輯器時,圖像應該位於郵件正文中。 我不想要附件。 而且我也不想將圖像轉換爲base64.Is還有其他方式嗎?如何在MFMailComposer消息主體中添加圖像(不作爲附件)
謝謝。
我想在作曲家中添加圖像,以便當我打開郵件編輯器時,圖像應該位於郵件正文中。 我不想要附件。 而且我也不想將圖像轉換爲base64.Is還有其他方式嗎?如何在MFMailComposer消息主體中添加圖像(不作爲附件)
謝謝。
你好我有工作使用下面的代碼,它的工作在iphone和ipad中完美。我有使用這段代碼的圖像文件。其工作代碼。
- (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];
}
你好,我有工作在iPhone上使用下面的代碼完美地工作和iPad。我有使用此代碼attacha圖像文件。其工作代碼。
和iOS 3.0或更高版本直接插在iPhone連接圖像
UIImage * image = [UIImage imageWithContentsOfFile:imagePath];
[composer addAttachmentData:UIImageJPEGRepresentation(itemImage, 1) mimeType:@"image/jpeg" fileName:@"MyFile.jpeg"];
這正是OP要求的。當然,如果您想要以PNG(或其他類型的圖像格式)發送,那麼您需要使用適當的UIImageXXXRepresentation函數和image/XXX MIME類型。 – hds 2012-08-27 10:38:20
//追加附件:
//Create a string with HTML formatting for the email body
NSMutableString *emailBody = [[NSMutableString alloc] initWithString:@"<html><body>"] ;
//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
NSString *filePath = @"";/*you file path*/
//Convert the file into data
NSData *attachmentData = [NSData dataWithContentsOfFile:filePath];
//Create a base64 string representation of the data using NSData+Base64
NSString *base64String = [attachmentData 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 *email = [[MFMailComposeViewController alloc] init];
email.mailComposeDelegate = self;
[email setSubject:@"My Inline Document"];
[email setMessageBody:emailBody isHTML:YES];
[self presentModalViewController:email animated:YES];
[email release];
[emailBody release];
文件路徑可以是任何文檔目錄路徑或NSBundle路徑。該文件可能是圖像/ pdf /附件。要執行上面的代碼,需要添加base64類進行編碼。 – RajKrish 2013-07-12 13:10:20
@parag嗨,你的代碼,不工作,當我檢查通過發送給收件人,它是作爲一個破碎的消息發送的。 – Ranjit 2012-08-30 12:30:36