[英]NSDocument app and file extension
我创建了一个基于文档的应用程序,该应用程序需要打开具有特定扩展名的xml文本文件。 当我使用NSDocument模板在Xcode中创建项目时,我指定了所需的扩展名,并且一切正常。
按照Apple关于如何构建基于文档的应用程序的指南,我去编辑Info.plist文件以添加以前缺少的UTI的详细信息。 突然,我的应用程序停止打开具有所需扩展名的文件,并且实际上停止了打开任何文件。 另外,当我尝试保存文件时,“保存”对话框不再建议任何扩展名。
当我保存文件并从终端运行命令mdls
时,我得到了
kMDItemContentTypeTree = (
"public.data",
"public.item"
)
而不是在Info.plist中为UTI设置的public.xml
。 看来我的应用程序停止了识别存储在Info.plist中的信息。 为了使此功能正常工作,我需要在Xcode中进行连接吗?
这是我的Info.plist文件的相关部分:
<key>CFBundleDocumentTypes</key>
<array>
<dict>
<key>CFBundleTypeExtensions</key>
<array>
<string>xmds</string>
</array>
<key>CFBundleTypeIconFile</key>
<string>AppIcon</string>
<key>CFBundleTypeName</key>
<string>XMDS Script</string>
<key>CFBundleTypeOSTypes</key>
<array>
<string>xmds</string>
</array>
<key>CFBundleTypeRole</key>
<string>Editor</string>
<key>LSItemContentTypes</key>
<array>
<string>com.dedalus.degs</string>
</array>
<key>NSDocumentClass</key>
<string>Document</string>
</dict>
</array>
<key>UTExportedTypeDeclarations</key>
<array>
<dict>
<key>UTTypeConformsTo</key>
<array>
<string>public.xml</string>
</array>
<key>UTTypeDescription</key>
<string>XMDS Script</string>
<key>UTTypeIconFile</key>
<string>AppIcon</string>
<key>UTTypeIdentifier</key>
<string>com.dedalus.degs</string>
<key>UTTypeTagSpecification</key>
<dict>
<key>com.apple.ostype</key>
<array>
<string>xmds</string>
</array>
<key>public.filename-extension</key>
<array>
<string>xmds</string>
</array>
</dict>
</dict>
</array>
我使用了Project的Target Info设置来设置文档类型和UTI,而不是Xcode 4.2和4.4中的Info.plist文件。 这将从Info.plist文件中提取并在更改后对其进行修改。 尝试改用它。
文档类型定义了将处理扩展名和扩展名的类。 导出的UTI代表您的应用具有权威性的扩展名。 看到这个Stackoverflow问题: Xcode 4中什么是“导入的UTI”?
我的导出的UTI符合public.data(“任何类型的简单字节流的基本类型,包括文件和内存中的数据”)。 如果使用标识符,请确保“文档类型”和“导出的UTI”中的标识符相同。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.