Custom Document Types

Using an Image as a Custom Document Type Icon in Xamarin.iOS.

PDF for offline use
Sample Code:
Related Articles:
Related SDKs:

Let us know how you feel about this

Translation Quality


0/250

last updated: 2016-12

This article covers including and managing an image asset in a Xamarin.iOS app to be used as a Custom Document Type Icon.

Document Icons

If a Xamarin.iOS app supports loading a particular document type, the developer can provide icons that the system will use when it encounters that document type, such as when a user holds down an attachment in the Mail Application as shown here:

The developer can add document type information for a file format the app is capable of opening by including dictionary entries for the CFBundleTypeName string and LSItemContentTypes array in the app's Info.plist. The icons for the document type go in the CFBundleTypeIconFiles array. If a document icon isn't provided, iOS will derive one from the app icon. Icons can be supplied for several sizes, optimized for the various device resolutions.

To assign these values in Xamarin Studio, use the Document Types section under the Advanced tab on the Info.plist editor to add the document type and assign image icons to it. For example, here is a screenshot showing registration for PDF support:

There is no advanced plist editor in Visual Studio at this time, so document icons have to be edited manually. Double click on the Info.plist file to open it, and add the following code under <plist><dict>:

<key>CFBundleDocumentTypes</key>
    <array>
        <dict>
            <key>CFBundleTypeIconFiles</key>
            <array>
                <string>Resources/doc_icon.png</string>
                <string>Resources/doc_icon@2x.png</string>
            </array>
            <key>CFBundleTypeName</key>
            <string>PDF</string>
            <key>LSHandlerRank</key>
            <string>Alternate</string>
            <key>LSItemContentTypes</key>
            <array>
                <string>com.adobe.pdf</string>
            </array>
        </dict>
    </array>

For more information about document types, see Apple’s Uniform Type Identifiers Reference and Document Interaction Programming Topics for iOS.

Xamarin Workbook

If it's not already installed, install the Xamarin Workbooks app first. The workbook file should download automatically, but if it doesn't, just click to start the workbook download manually.