Cocoa osx NSSharingServicePicker设置默认电子邮件地址

时间:2015-05-04 15:10:37

标签: macos cocoa email share items

在我的Mac应用中,我使用NSSharingServicePicker发送一些项目。我的问题是我想设置要发送的默认电子邮件地址。如何在邮件客户端打开时设置此值以显示它?

我有这段代码:

NSMutableArray *shareItems = [NSMutableArray arrayWithObject:@"MyText"];

NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *fileName = [NSString stringWithFormat:@"%@/MyFile.pdf", documentsDirectory];
NSURL* tempFileURL = [NSURL fileURLWithPath:fileName];

[shareItems addObject:tempFileURL];

NSSharingServicePicker *sharingPicker = [[NSSharingServicePicker alloc] initWithItems:shareItems];
sharingPicker.delegate = self;

这就是我想要的。我需要在电子邮件中设置默认目标地址。

enter image description here

抱歉我的英语不好。提前谢谢。

解决:

-(id<NSSharingServiceDelegate>)sharingServicePicker:(NSSharingServicePicker *)sharingServicePicker delegateForSharingService:(NSSharingService *)sharingService
{

    [sharingService setRecipients:@[@"email@email.com"]];
    [sharingService setSubject:@"MySubject"];

    return self;
}

1 个答案:

答案 0 :(得分:1)

NSSharingServiceNameComposeEmail通常是实现此目标的标准方法:

NSSharingService *service = [NSSharingService sharingServiceNamed:NSSharingServiceNameComposeEmail];
service.delegate = self;
service.recipients = @[@"tim.cook@apple.com"];
service.subject = [ NSString stringWithFormat:@"%@",NSLocalizedString(@"Re: Requested PDF",nil)];
[service performWithItems:shareItems];

虽然此代码可以与NSSharingServicePicker一起使用,但不清楚您使用shareItems做了什么,因此该文件将与正文一起附加。

enter image description here