问题描述
|
我有一个基于文档的应用程序,具有自定义文件格式,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之类的示例应用程序的复制者中复制并粘贴了条目,但无济于事。
尤其重要的是,保存的文档必须具有正确的UTI,因为它们需要自定义的QuickLook生成器,该生成器依赖于正确的UTI。
任何帮助是极大的赞赏。
先感谢您。
解决方法
您是否曾经做过以下事情:
1)在某个时候,将ѭ2作为您的UTI类型,然后,您在文件系统中创建了该类型的自定义文档。
3)然后,您在应用程序中更改了UTI设置。
4)您正在查看在步骤1中创建的文件的信息,并且该文件自创建以来是否未更改?
如果是这样,请尝试使用终端
touch
有问题的文件以对其进行Spotlight重新索引,然后再看一遍。
否则,它也可能有助于确保删除应用程序的所有无关副本,然后重新构建启动服务数据库(您可以使用我编写的实用程序:重新构建启动服务数据库。
通常,您的Info.plist信息可以,但是我建议以下操作:
如果您真的知道自己在做什么,则在ѭ5下的ѭ4中,仅指定OSType(文件类型代码)。这意味着您当然不会使用像\'appe\'
这样的全部为小写字母的类型,因为它们是为Apple保留的。我知道您需要向Apple注册创建者代码(约7英镑)(我自己做了几个工作),尽管我不确定文件类型以及他们是否仍在这样做。如果您指定一些任意文件类型代码,并且对过去30年中实际使用的代码不了解,那么就有可能与现有的已定义类型冲突。
更改您的文档UTI类型,使其更适合您的类型。 com.mycompany.appname.extension
之类的东西。
然后通过删除CFBundleTypeExtensions
条目并添加LSItemContentTypes
来更改文档CFBundleDocumentTypes
条目,如下所示:
<key>CFBundleDocumentTypes</key>
<array>
<dict>
<key>LSItemContentTypes</key>
<array>
<string>com.mycompany.appname.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>
然后,最后检查InfoPlist.strings
文件中的本地化版本是否覆盖了Info.plist中的所有键(如果有)。