NSSharingService

The NSSharingService class is used to provide a consistent user experience when sharing items on OS X. For example, items can be: NSURL objects, NSString objects, NSImage objects, video (through file URLs), or any object which implements the NSPasteboardWriting protocol.

For any item or group of items, the NSSharingService will display a sharing sheet to allow the user to pre-visualize what will be shared to the service. A sharing service can: create a post on a social network like Twitter or Facebook, send a message by email or iMessage, upload videos to viewing services, or send a file by AirDrop.

It's possible for developers to use NSSharingService directly. For instance, they can create a button that will trigger a service as shown in this code snippet:

Declaration

Parameters

items

The items to share.

Return Value

YEStrue if the service can share all the items; NOfalse otherwise. If items is nil, the method will return YEStrue when the service is configured.

Discussion

This method can be used to validate a custom user interface such as a dedicated Twitter button. Therefore you could call it once at launch time with nil items to check whether to display the button or not, and then with real items to enable and disable the button depending on the context or selection.

Declaration

Discussion

Each object in the array is an NSString object that contains the handle of a single recipient. The specific format of these handle varies from service to service. For example, some services use email addresses as handles.