How do I get my application to show up in the "Open in..." menu on iOS for a specific document type?
Q: How do I get my application to show up in the “Open in...” menu on iOS for a specific document type?
A: You need to register the document types that your application can open with iOS. To do this you need to add a document type to your app’s Info.plist for each document type that your app can open. Additionally if any of the document types are not known by iOS, you will need to provide an Uniform Type Identifier (UTI) for that document type.
Adding A Document Type
To add the document type do the following:
In your Xcode project, select the target you want to add the document type to.
Select the Info tab.
Click on the disclosure button for Document Types to open the document types.
Click the “+” button.
In the newly created document type :
Type the name of the document type.
In the “Types” section fill in the UTI for the new type.
Provide an icon for the document.
Click the disclosure triangle to open Additional document type properties.
Click in the table to add a new key and value.
For the key value type: CFBundleTypeRole.
For the value type: Editor.
Click the + button to add another key/value pair.
For the key value type: LSHandlerRank.
For the value type: Owner.
Adding A Custom UTI
If the document type you are adding is a custom document type, or a document type that iOS does not already know about, you will need to define the UTI for the document type. To add a new UTI do the following:
In your Xcode project select the target you want to add the new UTI to.
Select the Info tab.
Click on the disclosure button for Exported UTIs.
Click the “+” button.
Select “Add Exported UTI”.
In the Description field, fill in a description of the UTI.
In the Identifier field, fill in the identifier for the UTI.
In the Conforms To field fill in the list of UTIs that this new UTI conforms to.
Toggle the “Additional imported UTI properties” disclosure triangle to open up a table where you can add some additional information.
Click in the empty table and a list of items that can be added to the table will be displayed.
Type in “UTTypeTagSpecification”.
Set the type to Dictionary.
Click the disclosure triangle to open it, and click the + button in the table row to add an entry.
For the “New item” change the name to “public.filename-extension”.
For the type of the item change it to “Array”.
Toggle open the item you just added and click the + button in the table row.
For item 0 change the “value” to the file extension of your document. For example, txt, pdf, docx, etc.
Here is a concrete example of a custom document type and exported UTI. Let’s say you were adding a new document type of cat information and the file had an extension of catinfo then when you were finished with the steps above your information would look like this:
How To Test Your Custom Document Type
The easiest way to test your custom document type is to email your custom file to your iOS device. Navigate to the email and ensure that the attachment is there. Tap and hold the document attachment icon. This should open a popover on the iPad, or an action sheet on the iPhone, that shows all of the apps that open your document type. Your app should show up in the list. Tap your app icon and your app should launch and receive the document from the email.
If your property list is not set up correctly then attempting to open your custom document from mail may not work. Symptoms are that your custom app shows up in the list of apps for your custom document type but the attachment is never handed off to your app. Compare your custom document type to the one shown in Figure 1 of this Q&A. Carefully comparing your document type field by field to the example frequently reveals errors.
Here are a few things you should check when things are not working as expected:
The public.filename-extension key is spelled correctly.
The public.filename-extension key/value is defined as an array not a string.
Each item in the public.filename-extension array is a string that does not start with a dot. For example, txt not .txt.
The type in the document type and the identifier in the exported (or imported) UTI are exactly the same. Copying and pasting this value is the easiest way to ensure that the values are identical.
Uniform Type Identifiers Overview
Uniform Type Identifiers Reference
Information Property List Key Reference: Core Foundation Keys
System-Declared Uniform Type Identifiers
Document Revision History
Added sections on how to test your custom document type and troubleshooting tips.
New document that describes how to add document types to iOS applications so they can be opened from the Open in... menu.