A view controller that previews, opens, or prints files whose file format cannot be handled directly by your app.


class UIDocumentInteractionController : NSObject


Use this class to present an appropriate user interface for previewing, opening, copying, or printing a specified file. For example, an email program might use this class to allow the user to preview attachments and open them in other apps.

After presenting its user interface, a document interaction controller handles all interactions needed to support file preview and menu display.

You can also use the delegate to participate in interactions occurring within the presented interface. For example, the delegate is notified when a file is about to be handed off to another application for opening. For a complete description of the methods you can implement in your delegate, see UIDocumentInteractionControllerDelegate.


Creating the Document Interaction Controller

init(url: URL)

Creates and returns a new UIDocumentInteractionController object initialized with the specified URL.

Handling Document-Related Interactions

var delegate: UIDocumentInteractionControllerDelegate?

The delegate you want to receive document interaction notifications.

protocol UIDocumentInteractionControllerDelegate

A set of methods you can implement to respond to messages from a document interaction controller.

Presenting and Dismissing a Document Preview

func presentPreview(animated: Bool) -> Bool

Displays a full-screen preview of the target document.

func dismissPreview(animated: Bool)

Dismisses the currently active document preview.

Presenting and Dismissing Menus

func presentOptionsMenu(from: CGRect, in: UIView, animated: Bool) -> Bool

Displays an options menu and anchors it to the specified location in the view.

func presentOptionsMenu(from: UIBarButtonItem, animated: Bool) -> Bool

Displays an options menu and anchors it to the specified bar button item.

func presentOpenInMenu(from: CGRect, in: UIView, animated: Bool) -> Bool

Displays a menu for opening the document and anchors that menu to the specified view.

func presentOpenInMenu(from: UIBarButtonItem, animated: Bool) -> Bool

Displays a menu for opening the document and anchors that menu to the specified bar button item.

func dismissMenu(animated: Bool)

Dismisses the currently active menu.

Accessing the Target Document’s Attributes

var url: URL?

The URL identifying the target file on the local filesystem.

var uti: String?

The type of the target file.

var name: String?

The name of the target file.

var icons: [UIImage]

The images associated with the target file.

var annotation: Any?

Custom property list information for the target file.

Accessing the Controller Attributes

var gestureRecognizers: [UIGestureRecognizer]

The system-supplied gesture recognizers for presenting a document interaction controller.


Inherits From

See Also

Documents and Directories

Adding a Document Browser to Your App

Give users access to their local or remote documents from within your app.

Providing Access to Directories

Use a document picker to access the content of a directory outside your app’s container.

Building a Document Browser-Based App

Use a document browser to provide access to the user’s text files.

Building an App Based on the Document Browser View Controller

Implement a custom document file format to manage user interactions with files on different cloud storage providers.

class UIDocumentBrowserViewController

A view controller for browsing and performing actions on documents stored locally and in the cloud.

class UIDocumentPickerViewController

A view controller that provides access to documents or destinations outside your app’s sandbox.

Beta Software

This documentation contains preliminary information about an API or technology in development. This information is subject to change, and software implemented according to this documentation should be tested with final operating system software.

Learn more about using Apple's beta software