5

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?

hagi
  • 11,503
  • 3
  • 35
  • 48

3 Answers3

4

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.

hagi
  • 11,503
  • 3
  • 35
  • 48
  • Hi. So it sounds like having `UIDocumentPickerViewController` display custom icons for your own UTIs is only possible for the files you control (as you need to write the thumbnail out). If a user browses iCloud to say their shared iCloud ~/desktop folder and finds a .gpx file written by another app, there would be no way to specify the icon displayed? – Kyle Oct 30 '17 at 14:18
1

I believe you are using the wrong size icons in your CFBundleTypeIconFiles key. The size you are using are for the settings icon.

To test my theory, please add a few more files with different sizes. Plus all icons are square. The image you have in your question looks rectangular.

According to the section Icon and Image Design --> App Icon:

Document Icons

If your iOS app creates documents of a custom type, you want users to be able to recognize these documents at a glance. You don't need to design a custom icon for this purpose because iOS uses your app icon to create document icons for you.

And Excerpt from App Icons:

App icon (required) (iPhone)

  • 60 x 60 pixels
  • 120 x 120 pixels (@2x)

This is the main icon for apps running on iPhone and iPod touch in iOS 7 and later.

Settings icon (All devices)

  • 29 x 29 pixels
  • 58 x 58 pixels (@2x)
Black Frog
  • 11,595
  • 1
  • 35
  • 66
  • 1
    The sizes of the `CFBundleTypeIconFiles` icons are documented pretty clearly in [this document](https://developer.apple.com/library/mac/documentation/general/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html#//apple_ref/doc/uid/TP40009249-SW9)(Section: "Document Icons"), also linked in the question: "22 x 29 pixels / 44 x 58 pixels (high resolution)". They are neither squares nor have they been confused with the settings icons. We also have the normal app icons in our app, of course, but they aren't used either. – hagi Sep 02 '14 at 15:54
  • Do me a favor and list the normal app icons under the CFBundleTypeIconFiles in the plist also. When I get to my MacBook at home, I will do my own testing. – Black Frog Sep 02 '14 at 16:59
  • this is incorrect plz refer to offical https://developer.apple.com/library/ios/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html#//apple_ref/doc/uid/TP40009249-SW9 – Surjeet Rajput Sep 03 '16 at 06:20
1

I know this is very old but I got this working by adding the following to the exported UTI portion of Info.plist:

<key>UTTypeIconFiles</key>
<array>
    <string>Icon64.png</string>
</array>

I happen to try this first with a 64x64px image and it worked. I didn't try other sizes.

UTTypeSize64IconFile and UTTypeSize320IconFile don't seem to be used.

My tests were while running my iOS app on an iPhone simulator and real iPhone both using iOS 16.1 but I'm sure it works with earlier versions - just not sure how far back.

With the use of UTTypeIconFiles I at least see my app's icon in the Files app when I come across a file from my app with this UTI.

HangarRash
  • 7,314
  • 5
  • 5
  • 32