【问题标题】:iPhone SDK Add Image to the Body of an Email?iPhone SDK 将图像添加到电子邮件正文?
【发布时间】:2011-03-04 05:13:49
【问题描述】:

我想知道是否有人知道在打开邮件应用程序时如何在电子邮件正文中使用图像。有人可以帮忙吗?

在此先感谢基兰。

【问题讨论】:

标签: iphone image email sdk


【解决方案1】:
NSData *photoData = UIImageJPEGRepresentation([UIImage imageNamed:@"qwerty.png"], 1);
MFMailComposeViewController *viewController = [[MFMailComposeViewController alloc] init];
[viewController addAttachmentData:photoData mimeType:@"image/jpg" fileName:[NSString stringWithFormat:@"photo.png"]];

我是手工编写的代码,所以可能会有一些错误,但你应该明白大致的想法。

【讨论】:

  • 您好,感谢您的代码。它工作正常,但是当我单击按钮时没有任何反应?
【解决方案2】:

您可以使用 base64 编码在邮件正文中附加图像

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

NSData *imageData = UIImageJPEGRepresentation(image, 0.8);
NSString *imageStr = [imageData base64EncodingWithLineLength:[imageData length]];

NSString *htmlStr = [NSString stringWithFormat:@".....<img src='data:image/jpeg;base64,%@'>.......",imageStr];

[mailComposer setMessageBody:htmlStr isHTML:YES];
[self presentModalViewController:mailComposer animated:YES];
        [mailComposer release];

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-09-28
    • 2017-10-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-12-17
    • 2011-07-11
    • 1970-01-01
    相关资源
    最近更新 更多