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.
- iOS 8.0+
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
withSecurityScopeoption. This creates a bookmark containing a security-scoped URL.