views:

275

answers:

2

I'm trying to register an icon for my app's document type. After reading Declaring New Uniform Type Identifiers and looking at /Developer/Examples/Sketch I came up with something like this in my Info.plist:

<key>CFBundleDocumentTypes</key>
<array>
  <dict>
    <key>CFBundleTypeRole</key>
    <string>Viewer</string>
    <key>LSItemContentTypes</key>
    <array>
      <string>com.mycompany.myextension</string>
    </array>
    <key>NSDocumentClass</key>
    <string>NSString</string>
  </dict>
</array>

...

<key>UTExportedTypeDeclarations</key>
<array>
  <dict>
    <key>UTTypeDescription</key>
    <string>Blah blah blah</string>
    <key>UTTypeConformsTo</key>
    <array>
      <string>public.data</string>
    </array>
    <key>UTTypeIconFile</key>
    <string>My-file-icon.icns</string>
    <key>UTTypeIdentifier</key>
    <string>com.mycompany.myextension</string>
    <key>UTTypeTagSpecification</key>
    <dict>
      <key>public.filename-extension</key>
      <array>
        <string>myextension</string>
      </array>
    </dict>
  </dict>
</array>

Now, everything is fine and dandy, i.e. my program is opened when I click on a file with my extension, etc. However, the document icon is not registered with the OS, i.e. I see an ugly blank icon instead of my beautiful My-file-icon.icns. I suspect that I'm missing something in the plist above, any ideas?

+1  A: 

Your UTI declaration in the Info.plist appears to be correct, however I noticed an other issue. If you application is a document-based application you need to replace the NSString in following entry with your NSDocument subclass:

<key>NSDocumentClass</key>
<string>NSString</string>

For example it's "SKTDocument" in Sketch:

<key>NSDocumentClass</key>
<string>SKTDocument</string>

Edit: Please also make sure to use your own reverse domain name for your exported UTIs. This ensures that UTIs are unique. For example its com.mindnode.MindNode.MindNodeDocument in my case.

Markus Müller
Thanks, I'll fix that. Still don't understand why the icon doesn't get registered, though.
svintus
+1  A: 

Try putting the icon name in the CFBundleTypeIconFile key in the the CFBundleDocumentTypes array, not in the UTIExportedTypesDeclaration array.

And of course make sure that My-file-icon.icns is in your target's Copy Bundle Resources build phase and is being copied into Contents/Resources in your app's bundle.

cdespinosa
Yep, that was it. CFBundleTypeIconFile has to be in CFBundleDocumentTypes.
svintus