UIActivityViewController Class Reference
| Inherits from | |
| Conforms to | |
| Framework | /System/Library/Frameworks/UIKit.framework |
| Availability | Available in iOS 6.0 and later. |
| Declared in | UIActivityViewController.h |
Overview
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.
Tasks
Initializing the Activity View Controller
Accessing the Completion Handler
-
completionHandlerproperty
Excluding Specific Activity Types
-
excludedActivityTypesproperty
Properties
completionHandler
The completion handler to execute after the activity view controller is dismissed.
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.
Availability
- Available in iOS 6.0 and later.
Declared In
UIActivityViewController.hexcludedActivityTypes
The list of services that should not be displayed.
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.
Availability
- Available in iOS 6.0 and later.
Declared In
UIActivityViewController.hInstance Methods
initWithActivityItems:applicationActivities:
Initializes and returns a new activity view controller object that acts on the specified data.
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
UIActivityItemSourceprotocol, such asUIActivityItemProviderobjects. 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
niland must contain at least one object.- applicationActivities
An array of
UIActivityobjects representing the custom services that your application supports. This parameter may benil.
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.
Availability
- Available in iOS 6.0 and later.
Declared In
UIActivityViewController.hConstants
UIActivityViewControllerCompletionHandler
A completion handler to execute after the activity view controller is dismissed.
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
activityTypemethod of aUIActivityobject. For system-defined activities, it is one of the strings listed in "Built-in Activity Types” in UIActivity Class Reference.- completed
YESif the service was performed orNOif it was not. This parameter is also set toNOwhen the user dismisses the view controller without selecting a service.
Availability
- Available in iOS 6.0 and later.
Declared In
UIActivityViewController.h© 2013 Apple Inc. All Rights Reserved. (Last updated: 2013-04-23)