Mac Developer Library

Developer

AppKit Framework Reference NSSharingServiceDelegate Protocol Reference

Options
Deployment Target:

On This Page
Language:

NSSharingServiceDelegate

Inheritance


Not Applicable

Conforms To


Import Statement


Swift

import AppKit

Objective-C

@import AppKit;

Availability


Available in OS X v10.8 and later.

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.

  • 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.

    Declaration

    Swift

    optional func sharingService(_ sharingService: NSSharingService, sourceFrameOnScreenForShareItem item: NSPasteboardWriting) -> NSRect

    Objective-C

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

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.8 and later.

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

    Declaration

    Swift

    optional func sharingService(_ sharingService: NSSharingService, transitionImageForShareItem item: NSPasteboardWriting, contentRect contentRect: UnsafeMutablePointer<NSRect>) -> NSImage?

    Objective-C

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

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.8 and later.

  • Returns the window that contained the share items.

    Declaration

    Swift

    optional func sharingService(_ sharingService: NSSharingService, sourceWindowForShareItems items: [AnyObject], sharingContentScope sharingContentScope: UnsafeMutablePointer<NSSharingContentScope>) -> NSWindow?

    Objective-C

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

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.8 and later.

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

    Declaration

    Swift

    enum NSSharingContentScope : Int { case Item case Partial case Full }

    Objective-C

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

    Constants

    • Item

      NSSharingContentScopeItem

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

      Available in OS X v10.8 and later.

    • Partial

      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.

    • Full

      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.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.8 and later.