Document Types

Your app can declare itself willing to open documents of a certain type. In this way, if another app obtains a document of this type, it can propose to hand the document off to your app. For example, the user might download the document with Mobile Safari, or receive it in a mail message with the Mail app; now we need a way to get it from Safari or Mail to you.

To let the system know that your app is a candidate for opening a certain kind of document, you will configure the CFBundleDocumentTypes key in your Info.plist. This is an array, where each entry will be a dictionary specifying a document type by using keys such as LSItemContentTypes, CFBundleTypeName, CFBundleTypeIconFiles, and LSHandlerRank.

For example, suppose I want to declare that my app opens PDFs. My Info.plist could contain this simple entry (as seen in the standard editor):

Document types                       (1 item)
    Item 0                           (1 item)
        Document Content Type UTIs   (1 item)
            Item 0                   com.adobe.pdf

In Xcode 4, you can also specify document types by editing the target; switch to the Info tab. This same Info.plist entry would appear here as an untitled document type with com.adobe.pdf in the Types field.

Now suppose the user receives a PDF in an email message. The Mail app can display this PDF, but the user can also tap the Action button to bring up an action sheet containing two Open In buttons. The first button might actually specify my app as the default, but even if it doesn’t, tapping the second button will bring up a second action ...

Get Programming iOS 4 now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.