Class

UIDocumentPickerViewController

A UIDocumentPickerViewController object lets the user select documents or destinations outside your app’s sandbox. You must enable iCloud document support before you can use the document picker. For more information, see iCloud Design Guide.

Overview

Document Picker Modes

The document picker supports four modes. Each mode provides a slightly different approach to sharing files between apps.

  • Import an external document. The user selects an external document. The document picker copies the document, leaving the original unchanged.

  • Export a local document. The user selects an external destination. The document picker copies the document, leaving the original unchanged.

  • Open an external document. The user selects an external document. The document picker provides access to the document, letting the user edit the document in place.

  • Move a local document. The user selects an external destination. The document picker moves the document; however, you can still access the document as an external document, letting the user edit the document in place.

Working with External Documents

Both the open and move operations grant access to documents outside your app’s sandbox. This gives users an unprecedented amount of flexibility when it comes to working with their documents. However, it also adds a layer of complexity to your file handling. External documents have the following additional requirements:

  • The open and move operations provide security-scoped URLs for all external documents. Call the startAccessingSecurityScopedResource() method to access these documents and the stopAccessingSecurityScopedResource() method to release them. If you are using a UIDocument subclass to manage your document, it automatically manages the security-scoped URL for you.

  • Always use file coordinators to read and write to external documents.

  • Always use a file presenter when displaying the contents of an external document.

  • Don’t save any URLs provided by the open and move operations. You can, however, save a bookmark to these URLs. Call the the bookmarkData(options:includingResourceValuesForKeys:relativeTo:) method and pass in the withSecurityScope option. This creates a bookmark containing a security-scoped URL.

For more information on working with external documents, see Creating an Outstanding User Experience in App Extension Programming Guide.

Symbols

Creating a Document Picker

init(documentTypes: [String], in: UIDocumentPickerMode)

Initializes and returns a document picker that can import or open the given file types.

init(url: URL, in: UIDocumentPickerMode)

Initializes and returns a document picker that can export or move the given document.

Configuring a Document Picker

var delegate: UIDocumentPickerDelegate?

The document picker’s delegate.

var documentPickerMode: UIDocumentPickerMode

The type of file-transfer operation that the document picker performs.

Constants

UIDocumentPickerMode

Modes that define the type of file-transfer operation used by the document picker.