How to add a image in email body using MFMailComposeViewController

前端 未结 4 1677
故里飘歌
故里飘歌 2020-12-01 05:31

I am trying to find out the best way to add an image inside the body of the email and not as attachment in ios.

1) Apple has provided a function \"addAttach

4条回答
  •  情书的邮戳
    2020-12-01 06:00

    I've found that (at least in my case) a PNG will work in the message composer but NOT when the message is opened / received by the user.

    Composer Dandily showing logo PNG image!

    Viewer Not so much logo images over here.

    (Occasionally there will be a light blue outline where the image should be.)

    Using the HTML body string below and the conversion below that seems to do the trick.


    Message Body HTML String using JPEG

    NSString *body = [NSString stringWithFormat:
                      @"\
                      \
                        \
                            Check out the App!\
                            
    \ Isn't this a terriffic logo?!.\
    \ \
    \ CLICK ITTTTTTT! \ \ ", imageString, @"http://www.LOLamazingappLOL.com"];

    Convert Image to string with JPEG Data

    + (NSString *)dataStringFromImage:(UIImage *)image
    {
        NSData *imgData = UIImageJPEGRepresentation(image, 1);
        return [imgData base64EncodedStringWithOptions:kNilOptions];
    }
    

    Additional Info:

    • iOS Target = 8.0
    • iOS Device = 9.1
    • I am awful with HTML!

    Thank you @Richard for the CORRECT answer to this question.

提交回复
热议问题