iosxcodeios8uti

Show Icons for Custom UTIs in UIDocumentPickerViewController


The iOS app I'm working on exports a UTI. The relevant parts of the Info.plist look like this:

<key>UTExportedTypeDeclarations</key>
<array>
    <dict>
        <key>UTTypeConformsTo</key>
        <array>
            <string>public.xml</string>
            <string>public.data</string>
        </array>
        <key>UTTypeDescription</key>
        <string>GPX Document</string>
        <key>UTTypeIdentifier</key>
        <string>de.company.app.gpx</string>
        <key>UTTypeSize320IconFile</key>
        <string>Doc320.png</string>
        <key>UTTypeSize64IconFile</key>
        <string>Doc64.png</string>
        <key>UTTypeTagSpecification</key>
        <dict>
            <key>public.filename-extension</key>
            <array>
                <string>gpx</string>
            </array>
        </dict>
    </dict>
</array>

I want the app to handle GPX files via "Open in..." dialogues, so there's also a document type definition (which references the UTI) in the same PLIST:

<key>CFBundleDocumentTypes</key>
<array>
    <dict>
        <key>CFBundleTypeIconFiles</key>
        <array>
            <string>Icon29.png</string>
            <string>Icon58.png</string>
        </array>
        <key>CFBundleTypeName</key>
        <string>de.company.app.gpx</string>
        <key>CFBundleTypeRole</key>
        <string>Editor</string>
        <key>LSHandlerRank</key>
        <string>Owner</string>
        <key>LSItemContentTypes</key>
        <array>
            <string>de.company.app.gpx</string>
        </array>
    </dict>
</array>

When opening GPX files in Safari, it displays the icon I specified under CFBundleTypeIconFiles, i.e., Icon58.png on a retina device. The app also allows imports via the UIDocumentPickerViewController class introduced in iOS 8, and while the UTI definition works fine for filtering relevant files in iCloud Drive, it does not show any of my specified artwork:

I have ensured all the referenced image files (Icon29.png, Icon58.png, Doc64.png, Doc320.png) are indeed in the app bundle's root directory. The numbers in their names indicate their height in pixels. The Doc... files are squares, the other two follow this specification (iPhone only).

I've got basically two questions:

1) How do I make the UIDocumentPickerViewController display custom icons for our UTIs?

2) Are there any other use cases where UTTypeSize64IconFile and UTTypeSize320IconFile are used?


Solution

  • Unfortunately, the answer is that it cannot be done unless your app has control over how these files are written to disk. In that case, you can subclass UIDocument and write out thumbnails. Here is the original answer posted by an Apple engineer, posted on the Apple developer forums (login required). It includes a code sample to illustrate how it's done.

    I haven't found an answer to the second part of my question yet.