Question

I have an app that should try to save Markdown files. This is the relevant portions from my Info.plist:

<dict>
    <key>CFBundleTypeExtensions</key>
    <array>
        <string>md</string>
    </array>
    <key>CFBundleTypeIconFile</key>
    <string>icon.icns</string>
    <key>CFBundleTypeName</key>
    <string>Markdown document</string>
    <key>CFBundleTypeRole</key>
    <string>Editor</string>
    <key>LSItemContentTypes</key>
    <array>
        <string>net.daringfireball.markdown</string>
    </array>
    <key>LSHandlerRank</key>
    <string>Owner</string>
    <key>NSDocumentClass</key>
    <string>MyDocument</string>
    <key>NSExportableAs</key>
    <array>
        <string>Microsoft Word Document</string>
        <string>RTF</string>
        <string>HTML</string>
    </array>
    <key>NSExportableTypes</key>
    <array>
        <string>net.daringfireball.markdown</string>
        <string>com.microsoft.word.doc</string>
        <string>public.rtf</string>
        <string>public.html</string>
    </array>
</dict>

As you can see I also need the app to be able to export to doc, html and rtf.

Here is the UTExportedTypeDeclarations:

<dict>
    <key>UTTypeConformsTo</key>
    <array>
        <string>public.source</string>
    </array>
    <key>UTTypeDescription</key>
    <string>Markdown document</string>
    <key>UTTypeIdentifier</key>
    <string>net.daringfireball.markdown</string>
    <key>UTTypeTagSpecification</key>
    <dict>
        <key>public.filename-extension</key>
        <array>
            <string>md</string>
        </array>
    </dict>
</dict>

Now when I save a document in my app, and then run mdls on the file I get:

kMDItemContentType             = "dyn.ah62d4rv4ge8043a"
kMDItemContentTypeTree         = (
    "dyn.ah62d4rv4ge8043a",
    "public.data",
    "public.item"
)

Furthermore my app doesn't seem to be able to open the files it previously saved and gives an error:

Error Domain=NSCocoaErrorDomain Code=256 "The autosaved document “test10.md” could not be reopened. " UserInfo=0x102210bf0 {NSLocalizedDescription=The autosaved document “test10.md” could not be reopened. }

What am I doing wrong? How can I make it recognize my UTI properly?

Was it helpful?

Solution

I believe that your conforms-to is incorrect. You need to have a super-type from the physical and the functional trees.

There are many outdated things in the documentation, please see my writeup about what parts you really need nowadays. For example you don't need the exportable types any more: http://www.cocoanetics.com/2012/09/fun-with-uti/

regarding import/export. It depends if this app owns the file type. If it does it should export it. If not it should import it. Of all the apps exporting a type IIRC the latest one wins. Any app that is able to read your type should import it. Also apps that state that they are able to work with UTIs upwards from yours can open the file. e.g. if your format conforms to plain text, then TextEdit can also open it.

Also with your experimenting you might have inadvertenly messed up your launch services UTI registry. My article mentions a way to clean it.

OTHER TIPS

Guessing here, but if the types can already be on your system (which these two seem likely to be) maybe you should be importing them type instead of exporting them?

So instead of UTExportedTypeDeclarations these should be in UTImportedTypeDeclarations array.

from UTI overview

If your code relies on third-party UTI types that may not be present on the system, you should declare those UTIs as imported types in your bundle.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top