我正在使用MFMailComposerViewController
从 iOS 应用程序发送电子邮件。邮件可以正常工作,除非尝试添加图像。对我来说,图像的问题是使用它
我见过其他使用类似UIImage *emailImage = [UIImage imageNamed:@"myImageName.png"];
的例子:添加图像。我的图像是使用从数据库表中获取的[self.photo objectForKey:kPhotoPictureKey];
// mail
// Email Subject
NSString *emailTitle = @"Join. Download the iPhone app";
// Email Content
NSString *messageBody = @"http://www..com/";
// To address
NSArray *toRecipents = [NSArray arrayWithObject:@""];
UIImageView *mailImage = [[UIImageView alloc] init];
mailImage.image = [UIImage imageNamed:@"1.png"]; // placeholder image
mailImage.file = [self.photo objectForKey:kPhotoPictureKey];
[mailImage loadInBackground];
NSString *messageBody = [NSString stringWithFormat:@"http://www.example.com/<p><b><img src='data:image/png;base64,%@'></b></p>",mailImage.image];
MFMailComposeViewController *mc = [[MFMailComposeViewController alloc] init];
mc.mailComposeDelegate = self;
[mc setSubject:emailTitle];
[mc setMessageBody:messageBody isHTML:NO];
[mc setToRecipients:toRecipents];
// Present mail view controller on screen
[self presentViewController:mc animated:YES completion:NULL];