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

Image2:

要从文本中创建消息,我只能这样做:
NSURL * url;
url = [NSURL URLWithString:@"mailto:"
"?subject="
"&body=text"
];
(void) [[NSWorkspace sharedWorkspace] openURL:url];但我不知道该怎么做才能用图像来创造信息。
我找到了一种在使用ScriptingBridge框架时添加附件的方法。代码:
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添加到身体?
发布于 2013-01-18 01:21:57
就像这样:
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放在委托的头文件中。
https://stackoverflow.com/questions/13048258
复制相似问题