Add a document browser view controller to your app.
Setting up the document browser is a three-step process:
Set the browser as your app's root view controller.
Declare document browser support for your app.
Define the type of documents that the document browser can open.
The simplest way to do all three is to create a new project using the Document Based App template.
Create a New Document-Based App
To create a new document-based app, open Xcode and choose File > New > Project. In the template chooser, under Application, choose the Document Based App template, and click Next.
Continue following the prompts to create a document-based project. The following items appear in your new project:
Maincontains a document browser view controller as its initial view controller. This storyboard sets the document browser as your app's root view controller, ensuring that the browser remains in memory throughout your app's lifetime.
In your app's
UISupportskey is set to
YES, declaring document browser support for your app. Specifically, this key lets other apps open and edit the files stored in your app’s Documents directory. It also lets users set the app’s default save location in Settings. For more information, see UISupportsDocumentBrowser.
The app declares that it supports
publicdocument types. Users can then select image files in the document browser and share image files from other apps.
Use most of these default values as-is; however, unless you are making an image-based app, you probably need to update the supported document types.
Set the Supported Document Types
For each document type your app supports, follow these steps in the project editor's Info pane:
Click the Document Types disclosure triangle, and click the Add button (+) to add a new document type or open an existing document type.
Set the document type's name and its uniform type identifier (UTI).
Click the "Additional document type properties" disclosure triangle.
LSHandlerkey, and set its value to
Optionally, set the other document type properties.
For example, for an app that edits text files, use the settings shown in the following image:
These entries set the
CFBundle key in your app's
Info file as shown here:
For more information, see Set supported document types.