How to support files with a dynamic type identifier but a specific extension?

StackOverflow https://stackoverflow.com/questions/12904564

  •  07-07-2021
  •  | 
  •  

Question

I would like my app to support "Open In.." functionality for an existing file type.

This file type, however, does not have a UTI.

I ran mdls for it in Terminal with the following result:

kMDItemContentType             = "dyn.ah62d4rv4ge80c25t"

kMDItemContentTypeTree         = (
    "public.data",
    "public.item"
)

Given that info, I added to my plist:

<key>CFBundleDocumentTypes</key>
    <array>
        <dict>
            <key>CFBundleTypeExtensions</key>
            <array>
                <string>extension</string>
            </array>
            <key>LSHandlerRank</key>
            <string>Alternate</string>
            <key>CFBundleTypeRole</key>
            <string>Viewer</string>
            <key>LSItemContentTypes</key>
            <array>
                <string>public.data</string>
                <string>public.item</string>
            </array>
        </dict>
    </array>

However, this seems to ignore the "extension" and enables "Open In.." for any data file.

Is there any way to prevent this?

Était-ce utile?

La solution

You can define UTIs in your Info.plist. Make one up if this is for an extension of your own creation and put it under the "Exported Type UTIs". If it's for a known type of file but the UTI isn't well known, you can put it under the "Imported Type UTIs" section of your Info.plist. In either case, you can now reference this UTI in the Document types section.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top