NSSharingServiceDelegate Protocol Reference
| Conforms to | |
| Framework | /System/Library/Frameworks/AppKit.framework |
| Availability | Available in OS X v10.8 and later. |
| Declared in | NSSharingService.h |
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
-
– sharingService:sourceFrameOnScreenForShareItem: -
– sharingService:transitionImageForShareItem:contentRect: -
– sharingService:sourceWindowForShareItems:sharingContentScope:
Sharing Items
Instance Methods
sharingService:didFailToShareItems:error:
Invoked when the sharing service encountered an error when sharing items.
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.
See Also
Declared In
NSSharingService.hsharingService:didShareItems:
Invoked when the sharing service has finished sharing the items.
Parameters
- sharingService
The sharing service.
- items
The items being shared.
Availability
- Available in OS X v10.8 and later.
See Also
Declared In
NSSharingService.hsharingService: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.
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.hsharingService:sourceWindowForShareItems:sharingContentScope:
Returns the window that contained the share items.
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
NSSharingContentScopeItemby 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.hsharingService:transitionImageForShareItem:contentRect:
Invoked to allow returning a custom transition image when sharing an item.
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.hsharingService:willShareItems:
Invoked when the sharing service will share the specified items.
Parameters
- sharingService
The sharing service.
- items
The items being shared.
Availability
- Available in OS X v10.8 and later.
See Also
Declared In
NSSharingService.hConstants
NSSharingContentScope
The sharing scope constants specify the nature of the things you are sharing.
enum {
NSSharingContentScopeItem,
NSSharingContentScopePartial,
NSSharingContentScopeFull
};
typedef NSInteger NSSharingContentScope;
Constants
NSSharingContentScopeItemUsed 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.NSSharingContentScopePartialUsed 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.NSSharingContentScopeFullUsed 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.
© 2012 Apple Inc. All Rights Reserved. (Last updated: 2012-07-23)