How to set first Image after Some Text in Email body?

北城以北 提交于 2019-12-22 20:14:31

问题


I am using MFMailComposeViewController for sending the Email,

With this code I am able to get the Image, But image comes after the Text Detail, I wan't First Image and after Text,

Here is my code,

   MFMailComposeViewController *mail = [[MFMailComposeViewController alloc] init];
    mail.mailComposeDelegate = self;

    if ([MFMailComposeViewController canSendMail]) {
        //Setting up the Subject, recipients, and message body.
        [mail setToRecipients:[NSArray arrayWithObjects:Emailid,nil]];
        [mail setSubject:@"Receipt"];

        NSData *photoData = UIImageJPEGRepresentation([UIImage imageNamed:@"Gift.png"], 1);
        [mail addAttachmentData:photoData mimeType:@"image/jpg" fileName:[NSString stringWithFormat:@"photo.png"]];

        [mail setMessageBody:@"Receipt" isHTML:NO];
        NSString *emailBody;




        emailBody = [NSString stringWithFormat:@
                     "<br>Purchase Amount:            </br> "      "$  %@"
                     "<br>Amount Received:        </br> "      "$  %@"
                     "<br>Change:    </br> "      "$  %@"
                     ,AmountData,txtAmount.text,ChangeAmount.text];  


        [mail setMessageBody:emailBody isHTML:YES];

Please any body suggest me How can i do that?


回答1:


as of my knowledge this is the default behavior of the mfmailcomposeviewcontroller instead of just adding image as attachment you can do as below to show image first just to create body part

(void)createEmail {


NSMutableString *emailBody = [[[NSMutableString alloc] initWithString:@"<html><body>"] retain];
   [emailBody appendString:@"<p>Some email body text can go here</p>"];
   UIImage *emailImage = [UIImage imageNamed:@"myImageName.png"];
   NSData *imageData = [NSData dataWithData:UIImagePNGRepresentation(emailImage)];

   NSString *base64String = [imageData base64EncodedString];
  [emailBody appendString:[NSString stringWithFormat:@"<p><b><img src='data:image/png;base64,%@'></b></p>",base64String]];
  [emailBody appendString:@"</body></html>"];
    NSLog(@"%@",emailBody);

 //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];
}

this is shown here



来源:https://stackoverflow.com/questions/10069158/how-to-set-first-image-after-some-text-in-email-body

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!