NSSharingServiceDelegate Protocol Reference

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 NSSharingServiceDelegate protocol allows customization of the position and animation of the share sheet as well as be notified of the success or failure of the item being shared..

See NSSharingService Class Reference for more information.

Tasks

Customizing Transition Animation

Sharing Items

Instance Methods

sharingService:didFailToShareItems:error:

Invoked when the sharing service encountered an error when sharing items.

- (void)sharingService:(NSSharingService *)sharingService didFailToShareItems:(NSArray *)items error:(NSError *)error
Parameters
sharingService

The sharing service.

items

The items being shared.

error

The error that was encountered when trying to share the item. If the error is NSUserCancelledError, the user simply cancelled the error.

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

sharingService:didShareItems:

Invoked when the sharing service has finished sharing the items.

- (void)sharingService:(NSSharingService *)sharingService didShareItems:(NSArray *)items
Parameters
sharingService

The sharing service.

items

The items being shared.

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

sharingService:sourceFrameOnScreenForShareItem:

Invoked when the sharing service is performed and the sharing window is displayed, to present a transition between the original items and the sharing window.

- (NSRect)sharingService:(NSSharingService *)sharingService sourceFrameOnScreenForShareItem:(id < NSPasteboardWriting >)item
Parameters
sharingService

The sharing service.

item

The item being shared.

Return Value

The rectangle, in screen coordinates, to display the transition.

Discussion

The following is an example implementation of this method:

- (NSRect)sharingService:(NSSharingService *)sharingService sourceFrameOnScreenForShareItem:(id <NSPasteboardWriting>)item
{
    if ([item isKindOfClass:[NSImage class]]) {
        NSImage * image = [_imageView image];
        NSRect frame = [_imageView bounds];
        frame = [_imageView convertRect:frame toView:nil];
        frame.origin = [[_imageView window] convertBaseToScreen:frame.origin];
        return frame;
    }
    return NSZeroRect;
}
Availability
  • Available in OS X v10.8 and later.
Declared In
NSSharingService.h

sharingService:sourceWindowForShareItems:sharingContentScope:

Returns the window that contained the share items.

- (NSWindow *)sharingService:(NSSharingService *)sharingService sourceWindowForShareItems:(NSArray *)items sharingContentScope:(NSSharingContentScope *)sharingContentScope
Parameters
sharingService

The sharing service.

items

The items being shared.

sharingContentScope

The sharing content scope. The sharing scope can be modified from the default value of NSSharingContentScopeItem by setting a different value in the out parameter sharingContentScope. See “NSSharingContentScope” for supported values.

Return Value

The window of the shared items.

Discussion

The following is an example implementation of this method. It changes the item scope, and returns the window the source image view is contained within.

- (NSWindow *)sharingService:(NSSharingService *)sharingService
              sourceWindowForShareItems:(NSArray *)items
              sharingContentScope:(NSSharingContentScope *)sharingContentScope
{
    *sharingContentScope = NSSharingContentScopeItem;
    return [_imageView window];
}
Availability
  • Available in OS X v10.8 and later.
Declared In
NSSharingService.h

sharingService:transitionImageForShareItem:contentRect:

Invoked to allow returning a custom transition image when sharing an item.

- (NSImage *)sharingService:(NSSharingService *)sharingService transitionImageForShareItem:(id < NSPasteboardWriting >)item contentRect:(NSRect *)contentRect
Parameters
sharingService

The sharing service.

item

The shared item.

contentRect

The content rectangle is the frame of the actual content inside the transition image, excluding all decorations. For example, if the transition image is a QuickLook thumbnail, the value would be QLThumbnailGetContentRect.

Return Value

The image to display for the sharing transition. Its size should exactly match that of the original image.

Discussion

A sample implementation of this method:

- (NSImage *)sharingService:(NSSharingService *)sharingService
             transitionImageForShareItem:(id <NSPasteboardWriting>)item
             contentRect:(NSRect *)contentRect
{
    if ([item isKindOfClass:[NSImage class]]) {
        return [_imageView image];
    }
}
Availability
  • Available in OS X v10.8 and later.
Declared In
NSSharingService.h

sharingService:willShareItems:

Invoked when the sharing service will share the specified items.

- (void)sharingService:(NSSharingService *)sharingService willShareItems:(NSArray *)items
Parameters
sharingService

The sharing service.

items

The items being shared.

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

Constants

NSSharingContentScope

The sharing scope constants specify the nature of the things you are sharing.

enum {
   NSSharingContentScopeItem,
   NSSharingContentScopePartial,
   NSSharingContentScopeFull
};
typedef NSInteger NSSharingContentScope;
Constants
NSSharingContentScopeItem

Used when sharing a clearly identified item, for example, a file represented by its icon.

Available in OS X v10.8 and later.

Declared in NSSharingService.h.

NSSharingContentScopePartial

Used when sharing a portion of a more global content, for example, part of a webpage.

Available in OS X v10.8 and later.

Declared in NSSharingService.h.

NSSharingContentScopeFull

Used when sharing the whole content of the current document, for example, the URL of the webpage.

Available in OS X v10.8 and later.

Declared in NSSharingService.h.