iOS Developer Library

Developer

UIKit Framework Reference UIActivityItemProvider Class Reference

Options
Deployment Target:

On This Page
Language:

UIActivityItemProvider

Inheritance


Conforms To


Import Statement


Swift

import UIKit

Objective-C

@import UIKit;

Availability


Available in iOS 6.0 and later.

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.

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

    Declaration

    Swift

    init(placeholderItem placeholderItem: AnyObject)

    Objective-C

    - (instancetype)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.

    Import Statement

    Objective-C

    @import UIKit;

    Swift

    import UIKit

    Availability

    Available in iOS 6.0 and later.

  • Generates and returns the actual data-bearing object.

    Declaration

    Swift

    func item() -> AnyObject!

    Objective-C

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

    Import Statement

    Objective-C

    @import UIKit;

    Swift

    import UIKit

    Availability

    Available in iOS 6.0 and later.

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

    Declaration

    Swift

    var placeholderItem: AnyObject! { get }

    Objective-C

    @property(nonatomic, retain, readonly) id placeholderItem

    Import Statement

    Objective-C

    @import UIKit;

    Swift

    import UIKit

    Availability

    Available in iOS 6.0 and later.

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

    Declaration

    Swift

    var activityType: String? { get }

    Objective-C

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

    Import Statement

    Objective-C

    @import UIKit;

    Swift

    import UIKit

    Availability

    Available in iOS 6.0 and later.