需求:邮件body中的图片是直接展现的,不是以附件形式出现的
// 初始化
MFMailComposeViewController *mailComposeViewController = [[MFMailComposeViewController alloc]init];
1>.该图片是url类型:
NSString *emailBody = [NSString stringWithFormat:@"<p>%@</p>![](%@)",@"高圆圆",@"https://img.haomeiwen.com/i2030619/d1af03e042fda3fc.jpg?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240"];
[mailComposeViewController setMessageBody:emailBody isHTML:YES];
2>.图片是NSData类型:
NSData *imageData = messageObject.thumImage; // messageObject.thumImage是nsdata类型的图片
NSString *imageSource = [NSString stringWithFormat:@"data:image/png;base64,%@",[imageData base64EncodedStringWithOptions:NSDataBase64Encoding64CharacterLineLength]];
NSString *email = [NSString stringWithFormat:@"<img src = \"%@\"/>",imageSource];
[mailComposeViewController setMessageBody:email isHTML:YES];
3>.图片是UIimage类型的
先通过
imageData = UIImagePNGRepresentation(messageObject.thumImage);
或者
imageData = UIImageJPEGRepresentation(image,1.0)
转换成NSData类型去实现
如果想以依附件形式分享文件(图片,文件等都可以)
[mailComposeViewController addAttachmentData:imagedatat mimeType:@"png" fileName:@"hallDataBanner@2x"];
网友评论