UIActivityItemProvider Class Reference

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

Overview

A UIActivityItemProvider object is a proxy for data passed to an activity view controller. You can use a provider object in situations where you want to make data available for use by an activity but you want to delay providing that data until it is actually needed. For example, you might use a provider object to represent a large video file that needs to be processed before it can be shared to a user’s social media account.

When you initialize a UIActivityViewController object, you can pass a provider object in addition to any other data objects. When the user selects an activity, the activity view controller adds your provider object (which is also an operation object) to an operation queue so that it can begin to gather or process the needed data.

Subclassing Notes

You must subclass UIActivityItemProvider and implement its item method, which is called to generate the item data. You implement this method instead of the normal main method you would implement for an operation object. (The main method calls the item method when the operation object is executed.) Your implementation of the item method should do whatever work is necessary to create and return the data.

Tasks

Initializing the Provider

Accessing the Provider Attributes

Properties

activityType

The type of the activity object that is expecting the data. (read-only)

@property(nonatomic,readonly) NSString *activityType
Discussion

The value of this property is nil until the user selects an activity. At that time, the value is set and the provider object is submitted to a queue for execution. Thus, you should access this value only after your object’s item method is called.

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

placeholderItem

The placeholder object you specified at initialization time. (read-only)

@property(nonatomic,retain,readonly) id placeholderItem
Availability
  • Available in iOS 6.0 and later.
Declared In
UIActivityItemProvider.h

Instance Methods

initWithPlaceholderItem:

Initializes and returns a provider object with the specified placeholder data.

- (id)initWithPlaceholderItem:(id)placeholderItem
Parameters
placeholderItem

An object that can stand in for the actual object you plan to create. The contents of the object may be empty but the class of the object must match the class of the object you plan to provide later.

Return Value

An initialized provider object.

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

item

Generates and returns the actual data-bearing object.

- (id)item
Discussion

When the actual data-bearing object is required, this method is called by the provider object’s infrastructure. Subclasses must override this method and use it to perform whatever work is required to create the object and return it. You implement this method instead of the normal main method you would implement for operation objects. This method is called on a secondary thread of your app.

The system provides no built-in progress indicator, so if generating the item may take a long time you should plan on providing feedback in your app yourself.

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