NSSharingServicePicker Class Reference

Inherits from
Conforms to
Framework
/System/Library/Frameworks/AppKit.framework
Availability
Available in OS X v10.8 and later.
Declared in
NSSharingService.h
Related sample code

Overview

The NSSharingServicePicker class presents a list of sharing services, so that the user can choose a service to share an item. When a service is chosen, the picker automatically executes it, which presents the sharing window.

The NSSharingServicePickerDelegate allows customizing the picker’s available services, where it appears, and allows assigning the delegate object for the NSSharingService delegate.

Tasks

Creating a Sharing Service Picker

Display the Sharing Service Picker

Getting and Setting the Delegate

Properties

delegate

Specifies the service picker delegate.

@property(assign) id<NSSharingServicePickerDelegate> delegate
Discussion

The delegate object must conform to the NSSharingServicePickerDelegate delegate.

Availability
  • Available in OS X v10.8 and later.
Related Sample Code
Declared In
NSSharingService.h

Instance Methods

initWithItems:

Initializes a new sharing service picker for the selected items.

- (id)initWithItems:(NSArray *)items
Parameters
items

The items to be shared.

Return Value

A configured sharing service picker.

Discussion

The items represent the objects to be shared and must conform to the NSPasteboardWriting protocol, for example, NSString, NSImage, NSURL, etc. If the one of the items is an NSURL instance is a file URL (pointing to a video for example), then the content of the file will be shared. If the URL is remote, then the URL itself will be shared.

Availability
  • Available in OS X v10.8 and later.
Declared In
NSSharingService.h

showRelativeToRect:ofView:preferredEdge:

Shows the picker, populated with sharing services related to the instance items.

- (void)showRelativeToRect:(NSRect)rect ofView:(NSView *)view preferredEdge:(NSRectEdge)preferredEdge
Parameters
rect

The rectangle the picker should be showed relative to. The coordinates are in the view coordinate system. Passing NSZeroRect causes the view bounds to be used.

view

The view.

preferredEdge

The preferred edge of the view to display the picker. See NSRectEdge for the possible values.

Discussion

When the user selects one of the sharing services, the sharing service will be performed. This method must be called on mouse down by configuring the button used to trigger showing the picker to send its action on mouse down. You would typically do this by adding the following code to an appropriate awakeFromNib method:

- (void)awakeFromNib {
    NSButton *shareButton = self.mySharePickerButton; // your outlet to the button
    [shareButton sendActionOn:NSLeftMouseDownMask];
}

Here is an example implementation of the action method your share button would call:

- (IBAction)share:(id)sender
{
    NSArray * items = @[];
    NSSharingServicePicker * picker = [[NSSharingServicePicker alloc] initWithItems:items];
    picker.delegate = self;
    [picker showRelativeToRect:[sender bounds] ofView:sender preferredEdge:NSMinYEdge];
}
Availability
  • Available in OS X v10.8 and later.
Related Sample Code
Declared In
NSSharingService.h