How do I make a file that identifies as a custom UTI type?
Right now I have an application that generates an XML file. We'll call it someFile.myapp When my app saves the file and look at it using开发者_JAVA百科 mdls it has a kMDItemContentType of "dyn.234kdfsjk23jk24234kjfd" How can I get the UTI type of the file to be a custom value like com.mycompany.myapp?
UTIs are linked to extensions via a declaration in your application's Info.plist
file. Add a section like so:
<key>UTExportedTypeDeclarations</key>
<array>
<dict>
<key>UTTypeConformsTo</key>
<array>
<string>public.xml</string>
</array>
<key>UTTypeDescription</key>
<string>My Special File Type</string>
<key>UTTypeIdentifier</key>
<string>org.myapp.someutiidentifier</string>
<key>UTTypeTagSpecification</key>
<dict>
<key>public.filename-extension</key>
<array>
<string>myapp</string>
</array>
</dict>
</dict>
</array>
Dream up a unique extension for your file, and use an exported UTI declaration to associate the extension with your UTI.
Files are mapped to UTIs by Launch Services, which is theoretically able to use many different kinds of information about the file to identify its type, but in practice will disregard everything other than the file extension. Consequently, if you want your file's type to be identifiable, you need to come up with a unique extension and map it to the relevant type in your app's Info.plist. If your files need to share an extension that has already been claimed by another app, then you're SOL.
As far as I can see -- and I say this as a longtime Mac fan -- this is the one aspect of Mac OS X where it is really apt to say: "Welcome to 1985!"
精彩评论