Mac Developer Library

Developer

AppKit Framework Reference NSSharingServicePicker Class Reference

Options
Deployment Target:

On This Page
Language:

NSSharingServicePicker

Inheritance


Conforms To


Import Statement


Swift

import AppKit

Objective-C

@import AppKit;

Availability


Available in OS X v10.8 and later.

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.

  • Initializes a new sharing service picker for the selected items.

    Declaration

    Swift

    init(items items: [AnyObject])

    Objective-C

    - (instancetype)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.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.8 and later.

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

    Declaration

    Swift

    func showRelativeToRect(_ rect: NSRect, ofView view: NSView, preferredEdge preferredEdge: NSRectEdge)

    Objective-C

    - (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];
    • }

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.8 and later.