O'Reilly logo

Programming iOS 4 by Matt Neuburg

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required