6

How do you define the subject for a Mail message composed with NSSharingService?

I've been through the NSSharingService Class reference, but am not seeing it defined anywhere. The following successfully launches mail app, but subject is just shoved into the mail body along with the text.

NSAttributedString *text = [self.noteSynopsisView attributedString];
NSString *subject = @"My Subject";
NSArray *shareItems = [NSArray arrayWithObjects:text, subject, nil];
NSSharingServicePicker *sharingServicePicker = [[NSSharingServicePicker alloc] initWithItems:shareItems];
sharingServicePicker.delegate = self;
[sharingServicePicker showRelativeToRect:[self.shareButton bounds] ofView:self.shareButton preferredEdge:NSMaxYEdge];

In iOS, you'd normally do something like the following to define a subject for the MailComposer

[sharingServicePicker setSubject:@"My Subject"];

But SharingServicePicker does not support setSubject.

DenVog
  • 4,226
  • 3
  • 43
  • 72

2 Answers2

2

As of OS X 10.9, NSSharingService has a subject property which you can use.

goetz
  • 916
  • 6
  • 14
  • if ([mailShare respondsToSelector:@selector(setSubject:)] [mailShare setSubject:@"Subject"]; – Borzh Sep 26 '15 at 13:00
0

Implement the next method:

-(id<NSSharingServiceDelegate>)sharingServicePicker:(NSSharingServicePicker *)sharingServicePicker delegateForSharingService:(NSSharingService *)sharingService{
    sharingService.subject=@"Subject";
    return self;
}
daniel kilinskas
  • 3,538
  • 3
  • 16
  • 10