“com.apple”自定义文件格式的 UTI
我有一个基于文档的应用程序,具有自定义文件格式、UTI 等设置:
<key>CFBundleDocumentTypes</key>
<array>
<dict>
<key>CFBundleTypeExtensions</key>
<array>
<string>extension</string>
</array>
<key>CFBundleTypeIconFile</key>
<string>Icon</string>
<key>CFBundleTypeName</key>
<string>Custom Document</string>
<key>CFBundleTypeRole</key>
<string>Editor</string>
<key>LSHandlerRank</key>
<string>Default</string>
<key>NSDocumentClass</key>
<string>MyDocument</string>
</dict>
</array>
<key>UTExportedTypeDeclarations</key>
<array>
<dict>
<key>UTTypeConformsTo</key>
<array>
<string>public.data</string>
</array>
<key>UTTypeDescription</key>
<string>Custom Document</string>
<key>UTTypeIconFile</key>
<string>Icon</string>
<key>UTTypeIdentifier</key>
<string>com.mycompany.appname</string>
<key>UTTypeReferenceURL</key>
<string></string>
<key>UTTypeTagSpecification</key>
<dict>
<key>com.apple.ostype</key>
<string>XXXX</string>
<key>public.filename-extension</key>
<array>
<string>extension</string>
</array>
</dict>
</dict>
</array>
<key>UTImportedTypeDeclarations</key>
<array/>
哪个(我认为,根据我所读到的内容)是正确的方法。 除了,当我在任何保存的文件上运行 mdls 时,UTI 被列为:
kMDItemContentType = "com.apple.appname.document"
这很令人困惑,因为我已经从 TextEdit、iSpend 和 Sketch 等示例应用程序的 plist 中复制并粘贴了条目,但都无济于事。
保存的文档具有正确的 UTI 尤为重要,因为它们需要自定义 QuickLook 生成器,而该生成器依赖于正确的 UTI。
非常感谢任何帮助。 先感谢您。
I have a document-based app with a custom file format, the UTIs and such set up as so:
<key>CFBundleDocumentTypes</key>
<array>
<dict>
<key>CFBundleTypeExtensions</key>
<array>
<string>extension</string>
</array>
<key>CFBundleTypeIconFile</key>
<string>Icon</string>
<key>CFBundleTypeName</key>
<string>Custom Document</string>
<key>CFBundleTypeRole</key>
<string>Editor</string>
<key>LSHandlerRank</key>
<string>Default</string>
<key>NSDocumentClass</key>
<string>MyDocument</string>
</dict>
</array>
<key>UTExportedTypeDeclarations</key>
<array>
<dict>
<key>UTTypeConformsTo</key>
<array>
<string>public.data</string>
</array>
<key>UTTypeDescription</key>
<string>Custom Document</string>
<key>UTTypeIconFile</key>
<string>Icon</string>
<key>UTTypeIdentifier</key>
<string>com.mycompany.appname</string>
<key>UTTypeReferenceURL</key>
<string></string>
<key>UTTypeTagSpecification</key>
<dict>
<key>com.apple.ostype</key>
<string>XXXX</string>
<key>public.filename-extension</key>
<array>
<string>extension</string>
</array>
</dict>
</dict>
</array>
<key>UTImportedTypeDeclarations</key>
<array/>
Which (I assume, based on what I have read) is the correct way to do it.
Except, when I run mdls on any saved files, the UTI is listed as:
kMDItemContentType = "com.apple.appname.document"
This is confusing, as I have literally copied and pasted entries from plists of example apps like, TextEdit, iSpend, and Sketch, all to no avail.
It is especially important that saved documents have the correct UTI because they need a custom QuickLook generator, which relies on the correct UTI.
Any help is greatly appreciated.
Thank you in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您是否曾经执行过以下操作:
1) 在某个时刻,将
com.apple.appname.document
作为您的 UTI 类型,并且当时您在文件系统。3) 然后您在应用程序中更改了 UTI 设置。
4) 您正在查看在步骤 1 中创建的文件的信息,并且该文件自创建以来未曾更改?
如果是这样,请尝试使用终端
触摸
有问题的文件以强制对其进行 Spotlight 重新索引,然后再看一下。否则,确保删除应用程序的所有无关副本,然后重建启动服务数据库也可能有所帮助(您可以使用我编写的实用程序来执行此操作:重建启动服务数据库。
一般来说,您的 Info.plist 信息没问题,但我会推荐以下内容:
在您的
UTTypeTagSpecification
下的 UTExportedTypeDeclarations 仅在您确实知道自己在做什么时才指定 OSType(文件类型代码),这意味着您当然不会使用类似的类型。'appe'
全部为小写字母,因为这些字母是为 Apple 保留的。我知道您需要向 Apple 注册创建者代码 (CFBundleSignature
s)(我已经完成了)。一些我自己),尽管我不确定文件类型,以及他们是否仍在这样做,如果您指定一些任意文件类型代码并且不了解过去使用的实际代码。 30 年后,您将面临与现有定义类型发生冲突的风险。更改您的文档 UTI 类型,使其更适合您的类型。类似于
com.mycompany.appname.extension
。通过删除
CFBundleTypeExtensions
条目并添加LSItemContentTypes
来更改您的文档CFBundleDocumentTypes
条目,如下所示:然后, Info.plist 不会被
InfoPlist.strings
文件中的本地化版本覆盖(如果您有的话)。Did you at one point do the following:
1) At some point, had
com.apple.appname.document
as your UTI type, and at that time, you created a custom document of your type in the file system.3) You then changed the UTI settings in your app.
4) You are looking at the info for the file you created in step 1, and that file has not changed since it was created?
If so, try using the Terminal to
touch
the file in question to force a Spotlight re-index of it, then take another look.Otherwise, it might also help to make sure you remove all extraneous copies of your app and then rebuild the Launch Services Database (you can use a utility I wrote to do it: Rebuild Launch Services Database.
In general, your Info.plist info is OK, though I would recommend the following:
In your
UTExportedTypeDeclarations
under theUTTypeTagSpecification
, only specify an OSType (file type code) if you really know what you're doing. That means you of course aren't using a type like'appe'
that is all lowercase letters, as those are reserved for Apple. I know you were required to register creator codes (CFBundleSignature
s) with Apple (I've done several myself), though I'm not sure about file types, and whether they're still doing that or not. If you specify some arbitrary file type code and don't have a feel for what actual codes have come into use over the last 30 years, you risk conflicting with existing defined types.Change your document UTI type to be more specific to your type. Something like
com.mycompany.appname.extension
.Then change change your document
CFBundleDocumentTypes
entry by removing theCFBundleTypeExtensions
entry and adding aLSItemContentTypes
like the following:Then, finally check that any keys in your Info.plist aren't being overridden by localized versions in the
InfoPlist.strings
file, if you have one.