iOS Developer Library

Developer

UIKit Framework Reference UIActivityItemSource Protocol Reference

Options
Deployment Target:

On This Page
Language:

UIActivityItemSource

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.

Inheritance


Not Applicable

Import Statement


Swift

import UIKit

Objective-C

@import UIKit;

Availability


Available in iOS 6.0 and later.
  • Returns the placeholder object for the data. (required)

    Declaration

    Swift

    func activityViewControllerPlaceholderItem(_ activityViewController: UIActivityViewController) -> AnyObject

    Objective-C

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

    Import Statement

    Objective-C

    @import UIKit;

    Swift

    import UIKit

    Availability

    Available in iOS 6.0 and later.

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

    Declaration

    Swift

    func activityViewController(_ activityViewController: UIActivityViewController, itemForActivityType activityType: String) -> AnyObject?

    Objective-C

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

    Import Statement

    Objective-C

    @import UIKit;

    Swift

    import UIKit

    Availability

    Available in iOS 6.0 and later.

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

    Declaration

    Swift

    optional func activityViewController(_ activityViewController: UIActivityViewController, subjectForActivityType activityType: String?) -> String

    Objective-C

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

    Import Statement

    Objective-C

    @import UIKit;

    Swift

    import UIKit

    Availability

    Available in iOS 7.0 and later.

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

    Declaration

    Swift

    optional func activityViewController(_ activityViewController: UIActivityViewController, dataTypeIdentifierForActivityType activityType: String?) -> String

    Objective-C

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

    Import Statement

    Objective-C

    @import UIKit;

    Swift

    import UIKit

    Availability

    Available in iOS 7.0 and later.

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

    Declaration

    Swift

    optional func activityViewController(_ activityViewController: UIActivityViewController, thumbnailImageForActivityType activityType: String!, suggestedSize size: CGSize) -> UIImage!

    Objective-C

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

    Import Statement

    Objective-C

    @import UIKit;

    Swift

    import UIKit

    Availability

    Available in iOS 7.0 and later.