我正在尝试从 Mac 应用程序使用 NSSharingService 发送电子邮件。我将 HTML 代码作为电子邮件正文。当邮件窗口出现时,内容被格式化,但 HTML 结构中的图像被移动到底部电子邮件。此外,即使我将此图像定义为链接,该链接也不会在电子邮件正文中执行。
这是我使用的代码:
NSString* htmlText = @"<html><body><p>Message body</p><br/><a href='http://www.google.com'><img border='0' src=http://blog.jimdo.com/wp-content/uploads/2014/01/tree-247122.jpg label='Video' width='512' height='512'></img></a><br/><p>Video: <a href='http://blog.jimdo.com/wp-content/uploads/2014/01/tree-247122.jpg'>http://blog.jimdo.com/wp-content/uploads/2014/01/tree-247122.jpg</a></p><br/><p>Another link to <a href='http://www.google.com' target='_blank'>google</a></p></body></html>";
NSData* textData = [NSData dataWithBytes:[htmlText UTF8String] length:[htmlText lengthOfBytesUsingEncoding:NSUTF8StringEncoding]];
NSAttributedString* textAttributedString = [[NSAttributedString alloc] initWithHTML:textData options:nil documentAttributes:nil];
NSSharingService *emailSharingService = [NSSharingService sharingServiceNamed:NSSharingServiceNameComposeEmail];
[emailSharingService setSubject:@"Subject"];
emailSharingService.delegate = self;
NSArray* shareItems = [NSArray arrayWithObjects: textAttributedString, nil];
[emailSharingService performWithItems:shareItems];
图像应该出现在“消息正文”文本行之后和“视频:...”之前,但在我的例子中它出现在底部。
HTML 代码在 Firefox 和 Safari 上进行了测试。此外,我可以使用 Safari 打开 HTML 文本,然后选择“文件 -> 共享 -> 通过电子邮件发送此页面”,这正是我想要做的(但使用 Safari,而不是我的应用程序)。
欢迎提出任何想法。 提前致谢。
最佳答案
我使用 NSSharingService 进行了各种测试,包括连接 nsattributedstrings 和使用 NSTextAttachment,但 NSSharingService(或 NSAttributedString)似乎总是将图像推到最后。
尝试使用 Apple Scripting 桥。
关于objective-c - 如何避免图像重定位使用带有 HTML 内容的 NSSharingService 发送电子邮件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24820616/