1

「メールで共有」などを行うにはどうすればよいですか? NSSharingServicesメールを選択するときのように。たとえば、私はimage2NSImageのような結果を達成したいと考えています。どうすればいいですか?ポインタはありますか?

画像1:
ここに画像の説明を入力

画像2:
ここに画像の説明を入力

テキストのみからメッセージを作成するには、次のことができます。

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 を追加する方法は? Maby NSImage を一時ファイルに書き込んでから、添付ファイルとして追加して一時ファイルを削除する必要がありますか? または何?それとも、どうにかして NSImage を本体に追加する必要がありますか?

4

1 に答える 1

2

このような:

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 を必ず入れてください。

于 2013-01-18T01:21:57.977 に答える