2012-10-24 2 views
1

"메일에 공유"와 같은 기능을 수행하려면 어떻게해야합니까? 메일 편리 선택시 NSSharingServices처럼. 예를 들어 NSImage이 있고 결과를 image2과 같이 표현하고 싶습니다. 내가 어떻게 해? 어떤 포인터?앱에서 메일로 전송 된 이미지

이미지 1 :
enter image description here

이미지 2 : 텍스트에서 메시지를 작성하려면
enter image description here

은 내가 할 수있는 :

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를 작성한 다음 첨부 파일을 추가하고 임시 파일을 삭제해야합니까? 또는 무엇을? 또는 maby 어떻게 든 몸에 NSImage를 추가해야합니까? 이 같은

답변

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]; 

는 또한 대리인의 당신의 headerfile에 NSSharingServiceDelegate을 넣어 있는지 확인하십시오.

관련 문제