Sei sulla pagina 1di 9

UIActivityViewController Class Reference

UIActivityViewController Class Reference

Contents

UIActivityViewController Class Reference 3

Overview 3 Tasks 3 Initializing the Activity View Controller 3 Accessing the Completion Handler 4 Excluding Specific Activity Types 4 Properties 4 completionHandler 4 excludedActivityTypes 4 Instance Methods 5 initWithActivityItems:applicationActivities: 5 Constants 6 UIActivityViewControllerCompletionHandler 6

Document Revision History 8

2013-04-23

|

Copyright © 2013 Apple Inc. All Rights Reserved.

2

UIActivityViewController Class Reference

Inherits from

UIViewController : UIResponder : NSObject

Conforms to

NSCoding (UIViewController) UIAppearanceContainer (UIViewController) NSObject (NSObject)

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

– initWithActivityItems:applicationActivities: (page 5)

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

2013-04-23

|

Copyright © 2013 Apple Inc. All Rights Reserved.

3

UIActivityViewController Class Reference Properties

Accessing the Completion Handler

completionHandler (page 4) property

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

Excluding Specific Activity Types

excludedActivityTypes (page 4) property

The list of services that should not be displayed.

Properties

completionHandler

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

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

Availability Available in iOS 6.0 and later.

Declared in

UIActivityViewController.h

excludedActivityTypes

The list of services that should not be displayed.

2013-04-23

|

Copyright © 2013 Apple Inc. All Rights Reserved.

4

UIActivityViewController Class Reference Instance Methods

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

Availability Available in iOS 6.0 and later.

Declared in

UIActivityViewController.h

Instance Methods

initWithActivityItems:applicationActivities:

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

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

2013-04-23

|

Copyright © 2013 Apple Inc. All Rights Reserved.

5

UIActivityViewController Class Reference Constants

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

Constants

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 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 YES if the service was performed or NO if it was not. This parameter is also set to NO when the user dismisses the view controller without selecting a service.

Availability Available in iOS 6.0 and later.

2013-04-23

|

Copyright © 2013 Apple Inc. All Rights Reserved.

6

UIActivityViewController Class Reference Constants

Declared in

UIActivityViewController.h

2013-04-23

|

Copyright © 2013 Apple Inc. All Rights Reserved.

7

Document Revision History

This table describes the changes to UIActivityViewController Class Reference .

Date

Notes

2013-04-23

Named the task for the excludedActivityTypes property.

2012-09-19

New document that describes how to present app services to the user.

2013-04-23

|

Copyright © 2013 Apple Inc. All Rights Reserved.

8

Apple Inc. Copyright © 2013 Apple Inc. All rights reserved. No part of this publication

Apple Inc. Copyright © 2013 Apple Inc. All rights reserved.

No part of this publication may be reproduced, stored in a retrieval system, or transmitted, in any form or by any means, mechanical, electronic, photocopying, recording, or otherwise, without prior written permission of Apple Inc., with the following exceptions: Any person is hereby authorized to store documentation on a single computer for personal use only and to print copies of documentation for personal use provided that the documentation contains Apple’s copyright notice.

No licenses, express or implied, are granted with respect to any of the technology described in this document. Apple retains all intellectual property rights associated with the technology described in this document. This document is intended to assist application developers to develop applications only for Apple-labeled computers.

Apple Inc. 1 Infinite Loop Cupertino, CA 95014

408-996-1010

Apple, the Apple logo, iPad, iPhone, iPod, and iPod touch are trademarks of Apple Inc., registered in the U.S. and other countries.

iOS is a trademark or registered trademark of Cisco in the U.S. and other countries and is used under license.

Even though Apple has reviewed this document, APPLE MAKES NO WARRANTY OR REPRESENTATION, EITHER EXPRESS OR IMPLIED, WITH RESPECT TO THIS DOCUMENT, ITS QUALITY, ACCURACY, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE. AS A RESULT, THIS DOCUMENT IS PROVIDED “AS IS,” AND YOU, THE READER, ARE ASSUMING THE ENTIRE RISK AS TO ITS QUALITY AND ACCURACY.

IN NO EVENT WILL APPLE BE LIABLE FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES RESULTING FROM ANY DEFECT OR INACCURACY IN THIS DOCUMENT, even if advised of the possibility of such damages.

THE WARRANTY AND REMEDIES SET FORTH ABOVE ARE EXCLUSIVE AND IN LIEU OF ALL OTHERS, ORAL OR WRITTEN, EXPRESS OR IMPLIED. No Apple dealer, agent, or employee is authorized to make any modification, extension, or addition to this warranty.

Some states do not allow the exclusion or limitation of implied warranties or liability for incidental or consequential damages, so the above limitation or exclusion may not apply to you. This warranty gives you specific legal rights, and you may also have other rights which vary from state to state.