iOS Developer Library — Pre-Release

Developer

UIKit Framework Reference UIActivityViewController Class Reference

Options
Deployment Target:

On This Page
Language:

UIActivityViewController

Inheritance


Conforms To


Import Statement


Swift

import UIKit

Objective-C

@import UIKit;

Availability


Available in iOS 6.0 and later.

The UIActivityViewController class is a standard view controller that you can use to offer various services from your application. The system provides several standard services, such as copying items to the pasteboard, posting content to social media sites, sending items via email or SMS, and more. Apps can also define custom services.

Your app is responsible for configuring, presenting, and dismissing this view controller. Configuration for the view controller involves specifying the data objects on which the view controller should act. (You can also specify the list of custom services your app supports.) When presenting the view controller, you must do so using the appropriate means for the current device. On iPad, you must present the view controller in a popover. On iPhone and iPod touch, you must present it modally.

  • Initializes and returns a new activity view controller object that acts on the specified data.

    Declaration

    Swift

    init(activityItems activityItems: [AnyObject], applicationActivities applicationActivities: [AnyObject]?)

    Objective-C

    - (instancetype)initWithActivityItems:(NSArray *)activityItems applicationActivities:(NSArray *)applicationActivities

    Parameters

    activityItems

    The array of data objects on which to perform the activity. The type of objects in the array is variable and dependent on the data your application manages. For example, the data might consist of one or more string or image objects representing the currently selected content.

    Instead of actual data objects, the objects in this array can be objects that adopt the UIActivityItemSource protocol, such as UIActivityItemProvider objects. Source and provider objects act as proxies for the corresponding data in situations where you do not want to provide that data until it is needed.

    This array must not be nil and must contain at least one object.

    applicationActivities

    An array of UIActivity objects representing the custom services that your application supports. This parameter may be nil.

    Return Value

    The activity view controller to present.

    Discussion

    It is your responsibility to present and dismiss the view controller using the appropriate means for the given device idiom. On iPad, you must present the view controller in a popover. On other devices, you must present it modally.

    Import Statement

    Objective-C

    @import UIKit;

    Swift

    import UIKit

    Availability

    Available in iOS 6.0 and later.

  • The completion handler to execute after the activity view controller is dismissed.

    Declaration

    Swift

    var completionWithItemsHandler: UIActivityViewControllerCompletionWithItemsHandler?

    Objective-C

    @property(nonatomic, copy) UIActivityViewControllerCompletionWithItemsHandler completionWithItemsHandler

    Discussion

    When the user-selected service finishes operating on the data, or when the user dismisses the view controller, the view controller executes this completion handler to let your app know the final result of the operation.

    Import Statement

    Objective-C

    @import UIKit;

    Swift

    import UIKit

    Availability

    Available in iOS 8.0 and later.

  • The completion handler to execute after the activity view controller is dismissed.

    Deprecation Statement

    Use the completionWithItemsHandler property instead.

    Declaration

    Swift

    var completionHandler: UIActivityViewControllerCompletionHandler?

    Objective-C

    @property(nonatomic, copy) UIActivityViewControllerCompletionHandler completionHandler

    Discussion

    When the user-selected service finishes operating on the data, or when the user dismisses the view controller, the view controller executes this completion handler to let your app know the final result of the operation.

    Import Statement

    Objective-C

    @import UIKit;

    Swift

    import UIKit

    Availability

    Available in iOS 6.0 and later.

    Deprecated in iOS 8.0.

  • The list of services that should not be displayed.

    Declaration

    Swift

    var excludedActivityTypes: [AnyObject]?

    Objective-C

    @property(nonatomic, copy) NSArray *excludedActivityTypes

    Discussion

    This property contains an array of strings, each of which corresponds to the value you would find in the activityType parameter of a UIActivity object. Each string you specify indicates a service that you do not want displayed to the user. You might exclude services that you feel are not suitable for the content you are providing. For example, you might not want to allow the user to print a specific image. If the value of this property is nil, no services are excluded.

    This value of this property is nil by default.

    Import Statement

    Objective-C

    @import UIKit;

    Swift

    import UIKit

    Availability

    Available in iOS 6.0 and later.

Data Types

  • A completion handler to execute after the activity view controller is dismissed.

    Declaration

    Swift

    typealias UIActivityViewControllerCompletionWithItemsHandler = (String!, Bool, [AnyObject]!, NSError!) -> Void

    Objective-C

    typedef void (^UIActivityViewControllerCompletionWithItemsHandler)(NSString *activityType, BOOL completed, NSArray *returnedItems, NSError *activityError);

    Discussion

    Upon the completion of an activity, or the dismissal of the activity view controller, the view controller’s completion block is executed. You can use this block to execute any final code related to the service. The parameters of this block are as follows:

    activityType

    The type of the service that was selected by the user. For custom services, this is the value returned by the activityType method of a UIActivity object. For system-defined activities, it is one of the strings listed in "Built-in Activity Types” in UIActivity Class Reference.

    completed

    YEStrue if the service was performed or NOfalse if it was not. This parameter is also set to NOfalse when the user dismisses the view controller without selecting a service.

    returnedItems

    An array of NSExtensionItem objects containing any modified data. Use the items in this array to get any changes made to the original data by an extension. If no items were modified, the value of this parameter is nil.

    activityError

    An error object if the activity failed to complete, or nil if the the activity completed normally.

    Import Statement

    Objective-C

    @import UIKit;

    Swift

    import UIKit

    Availability

    Available in iOS 8.0 and later.

  • A completion handler to execute after the activity view controller is dismissed.

    Use UIActivityViewControllerCompletionWithItemsHandler instead.

    Declaration

    Swift

    typealias UIActivityViewControllerCompletionHandler = (String!, Bool) -> Void

    Objective-C

    typedef void (^UIActivityViewControllerCompletionHandler)(NSString *activityType, BOOL completed);

    Discussion

    Upon the completion of an activity, or the dismissal of the activity view controller, the view controller’s completion block is executed. You can use this block to execute any final code related to the service. The parameters of this block are as follows:

    activityType

    The type of the service that was selected by the user. For custom services, this is the value returned by the activityType method of a UIActivity object. For system-defined activities, it is one of the strings listed in "Built-in Activity Types” in UIActivity Class Reference.

    completed

    YEStrue if the service was performed or NOfalse if it was not. This parameter is also set to NOfalse when the user dismisses the view controller without selecting a service.

    Import Statement

    Objective-C

    @import UIKit;

    Swift

    import UIKit

    Availability

    Available in iOS 6.0 and later.