我生成一个包含base64图像的html字符串。当MFMailComposeViewController打开时,我会看到生成的电子邮件中的图像。当我发送并打开它时,图像不会显示,只有空方块。
我的代码
- (IBAction)actionShareByEmail:(id)sender {
if([MFMailComposeViewController canSendMail])
{
MFMailComposeViewController *picker = [[MFMailComposeViewController alloc] init];
picker.mailComposeDelegate = self;
NSString* subject = @"Environments list with qrcode";
[picker setSubject:subject];
[picker setMessageBody:[manager getHtmlWithEnvironments:nil] isHTML:YES];
[self presentViewController:picker animated:YES completion:nil];
}
}
-(NSString*)getHtmlWithEnvironments:(NSArray*)envDictionnaries{
NSMutableString* html = [[NSMutableString alloc]init];
[html appendString: @"<html><body>"];
for (NSDictionary *d in self.arEnvironments) {
UIImage* qrcode = [QRCodeGenerator qrImageForString:[d objectForKey:@"env_name"] imageSize:200.0];//Works fine
NSData *imageData = UIImagePNGRepresentation(qrcode);
NSString *encodedString = [imageData base64EncodedStringWithOptions:NSDataBase64Encoding64CharacterLineLength];
[html appendString: [NSString stringWithFormat:@"<H3>%@</h3><img src=\"data:image/png;base64,%@\" width=\"200\" height=\"200\" alt=\"test\" /></br></br>",[d objectForKey:KEY_ENV_NAME],encodedString]];
}
[html appendString: @"</html><body>"];
return html;
}
如何正确显示图像?