goe*_*goe 6 macos objective-c html-email
我正在尝试使用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];
Run Code Online (Sandbox Code Playgroud)
图像应出现在"消息体"文本行之后和"视频:..."之前,但在我的情况下它出现在底部.
HTML代码在Firefox和Safari上进行测试.此外,我可以使用Safari打开HTML文本,然后选择"文件 - >共享 - >通过电子邮件发送此页面"它正是我正在尝试做的事情(但使用Safari,而不是我的应用程序).
任何想法都很好.提前致谢.
我使用 NSSharingService 进行了各种测试,包括连接 nsattributedstring 和使用 NSTextAttachment,但似乎 NSSharingService (或 NSAttributedString)总是将图像推到末尾。
尝试使用 Apple 脚本桥。
| 归档时间: |
|
| 查看次数: |
606 次 |
| 最近记录: |