UIActivityItemSource Protocol Reference

Conforms to
Framework
/System/Library/Frameworks/UIKit.framework
Availability
Available in iOS 6.0 and later.
Declared in
UIActivityItemProvider.h
Related sample code

Overview

The UIActivityItemSource protocol defines the methods used by a UIActivityViewController object to retrieve the data items to act on. You can use this protocol in situations where you want to provide the data from one of your app’s existing objects instead of creating a separate UIActivityItemProvider object. When implementing this protocol, your object becomes the data provider, providing the view controller with access to the items.

Because the methods of this protocol are executed on your app’s main thread, you should avoid using this protocol in cases where the data objects might take a significant amount of time to create. When creating large data objects, consider using a UIActivityItemProvider object instead.

Tasks

Getting the Data Items

Providing Information About the Data Items

Instance Methods

activityViewController:dataTypeIdentifierForActivityType:

For items that are provided as NSData, returns the UTI for the item.

- (NSString *)activityViewController:(UIActivityViewController *)activityViewController dataTypeIdentifierForActivityType:(NSString *)activityType;
Parameters
activityViewController

The activity view controller object requesting information about the data item.

activityType

The selected activity type; may be nil.

Return Value

The UTI for the item.

Discussion

Providing the UTI allows services to handle specific data types in appropriate ways, such as an email service formatting an image to display in-line. If you provide items as NSData objects, implement this method to allow those services to better handle your data.

Availability
  • Available in iOS 7.0 and later.
Declared In
UIActivityItemProvider.h

activityViewController:itemForActivityType:

Returns the data object to be acted upon. (required)

- (id)activityViewController:(UIActivityViewController *)activityViewController itemForActivityType:(NSString *)activityType
Parameters
activityViewController

The activity view controller object requesting the data item.

activityType

The type of activity to be performed with the data object. You can use this string to decide how best to prepare the data object.

Return Value

The final data object to be acted on. May be nil if multiple items were registered for a single activity type, so long as one of the items returns an actual value.

Discussion

This method returns the actual data object to be acted on by an activity object. Your implementation of this method should create or generate the data object and return it as quickly as possible.

Availability
  • Available in iOS 6.0 and later.
Declared In
UIActivityItemProvider.h

activityViewController:subjectForActivityType:

For activities that support a subject field, returns the subject for the item.

- (NSString *)activityViewController:(UIActivityViewController *)activityViewController subjectForActivityType:(NSString *)activityType;
Parameters
activityViewController

The activity view controller object requesting information about the data item.

activityType

The selected activity type; may be nil.

Return Value

A string to use as the contents of the subject field.

Discussion

When posting an item the service may provide for a separate subject field and data field, such as an email message. Implement this method if you wish to provide a subject field for services that support one.

Availability
  • Available in iOS 7.0 and later.
Declared In
UIActivityItemProvider.h

activityViewController:thumbnailImageForActivityType:suggestedSize:

For activities that support a preview image, returns a thumbnail preview image for the item.

- (UIImage *)activityViewController:(UIActivityViewController *)activityViewController thumbnailImageForActivityType:(NSString *)activityType suggestedSize:(CGSize)size;
Parameters
activityViewController

The activity view controller object requesting information about the data item.

activityType

The selected activity type.

size

The suggested size for the thumbnail image, in points. You should provide an image using the appropriate scale for the screen. Images provided at the suggested size will result in the best experience.

Return Value

The image to use as a preview for the item.

Availability
  • Available in iOS 7.0 and later.
Declared In
UIActivityItemProvider.h

activityViewControllerPlaceholderItem:

Returns the placeholder object for the data. (required)

- (id)activityViewControllerPlaceholderItem:(UIActivityViewController *)activityViewController
Parameters
activityViewController

The activity view controller object requesting the placeholder item.

Return Value

An object to use as a placeholder for the actual data.

Discussion

This method returns an object that can be used as a placeholder for the real data. Placeholder objects do not have to contain any real data but should be configured as closely as possible to the actual data object you intend to provide. In general the actual value should match in type but it is possible to return a different type of data for activityViewController:itemForActivityType:. It should be one that the activity can handle otherwise you may get an activity with empty content. For example, the placeholder could be a UIImage object but the actual value could be an NSData object with PDF information.

Availability
  • Available in iOS 6.0 and later.
Declared In
UIActivityItemProvider.h