首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >从应用程序到邮件的图像

从应用程序到邮件的图像
EN

Stack Overflow用户
提问于 2012-10-24 11:25:12
回答 1查看 742关注 0票数 1

我怎么能做“分享邮件”之类的事情呢?就像在NSSharingServices中选择邮件一样。例如,我有NSImage,我想取得类似于image2那样的结果。我该怎么做呢?有什么指示吗?

Image1:

Image2:

要从文本中创建消息,我只能这样做:

代码语言:javascript
复制
NSURL *     url;
url = [NSURL URLWithString:@"mailto:"
       "?subject="
       "&body=text"
       ];
(void) [[NSWorkspace sharedWorkspace] openURL:url];

但我不知道该怎么做才能用图像来创造信息。

我找到了一种在使用ScriptingBridge框架时添加附件的方法。代码:

代码语言:javascript
复制
MailApplication *mail = [SBApplication
                         applicationWithBundleIdentifier:@"com.apple.Mail"];

MailOutgoingMessage *emailMessage =
[[[mail classForScriptingClass:@"outgoing message"] alloc]
 initWithProperties:
 [NSDictionary dictionaryWithObjectsAndKeys:
  @"this is my subject", @"subject",
  @"this is my content", @"content",
  nil]];

[[mail outgoingMessages] addObject: emailMessage];

emailMessage.visible = YES;


NSString *attachmentFilePath = [NSString stringWithUTF8String:"<my provided file path>"];
if ( [attachmentFilePath length] > 0 ) {

    MailAttachment *theAttachment = [[[mail
                                       classForScriptingClass:@"attachment"] alloc]
                                     initWithProperties:
                                     [NSDictionary dictionaryWithObjectsAndKeys:
                                      attachmentFilePath, @"fileName",
                                      nil]];

    [[emailMessage.content attachments] addObject: theAttachment];
}
[emailMessage visible];

它起作用了。但是如何将NSImage添加到附件中呢?我要把NSImage写到临时文件中,然后作为附件添加并删除临时文件?不然呢?或者我应该以某种方式将NSImage添加到身体?

EN

回答 1

Stack Overflow用户

发布于 2013-01-18 01:21:57

就像这样:

代码语言:javascript
复制
NSString *text = @"sometext";
NSImage *image = [[NSImage alloc] initWithContentsOfURL:[NSURL URLWithString:@"/logo57.png"]];
NSArray * shareItems = [NSArray arrayWithObjects:text, image, nil];

NSSharingService *service = [NSSharingService sharingServiceNamed:NSSharingServiceNameComposeEmail];
service.delegate = self;
[service performWithItems:shareItems];

还要确保将NSSharingServiceDelegate放在委托的头文件中。

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/13048258

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档