iOS Tips and Tricks: Associate a File Type with your App - Part 1

If your App consumes files, you'll need to figure out how you want your users to get their files to your App. For iOS applications you essentially have 3 options. 

1. File Type Association

2. iTunes

3. Various Cloud Services (DropBox, Google Drive, SkyDrive, Box.Net etc...)

In this article I will will walk you through the first option and i'll be breaking it into 3 parts. 

The first part will be using known UTI's (Uniform Type Identifiers), such as PDF. The second part will be registering your own file extension. And the third part will be showing you where to find the files you opened

Before we get started, let me explain what i mean by "File Type Association".  Basically, in iOS your App can register itself as a source for specific File Types.

For example, I wrote an Application called "OpenPDF". In that App I registered for the "PDF" file type. Thus, when i go to my e-mail and open up a PDF, i can click the "Open In" button and select my App: 

If i had bothered to have an icon for my app, you would also see my app's icon :)

SO, how did i do that?!?

Well, since PDF is a known file type, its actually very easy. 

1. Click on your project and select the info tab

2. Notice the Sections at the bottom. The first one is called "Document Types".  Expand that section and click the "+" button at the bottom. 

3. For the "Name" field, you can put anything, however for the "Types" field you need to put the correct UTI (Uniform Type Identifiers) for it.  For a list of known UTI's for iOS check out Apple's Documentation. If you looked up PDF in that document, you would see that the Identifier is: com.adobe.pdf. 

The last part of this step is to expand the "Additional document type properties(0)" and enter a key and value. Now a lot snippets i've seen online say that the key should be: "LSHandlerRank" and the value should be: "Alternate". However, I couldn't actually find any documents from Apple that say that. Now you do need a key/value there, but it looks like you can put whatever you want in there. 

And thats it. If you were to run your App now, and tried to open a PDF file via an "Open In Dialog" from another app, you can launch your app. 

Stay tuned for Part 2 where i show you how to register your own file type and Part 3 where i show you where those files you opened actually go, so that you can interact with them. 

By Stephen Zaharuk (SteveZ)




Tags / ,