如何在plist文件中定义统一类型标识符? [英] How to define a Uniform Type Identifier in a plist file?
问题描述
我的应用程序使用以下 NSApplicationDelegate
函数。
My application uses the following NSApplicationDelegate
function.
- (void)application:(NSApplication*)sender openFiles:(NSArray*)filenames;
我想使用此功能使用户能够拖放图像文件到码头上的应用程序图标。
I want to use this function to enable the user to drag and drop image files onto the application icon in the dock.
如何在我的 plist
文件中定义某些文件类型以限制他们成为图像?我发现结构看起来像这样。
How do I have to define certain file types in my plist
file to restrict them to be images? I found out the structure has to look something like this.
// plist file contents taken from Preview.app
[...]
<key>CFBundleDocumentTypes</key>
<array>
<dict>
<key>CFBundleTypeIconFile</key>
<string>jpeg.icns</string>
<key>CFBundleTypeRole</key>
<string>Viewer</string>
<key>LSIsAppleDefaultForType</key>
<true/>
<key>LSItemContentTypes</key>
<array>
<string>public.jpeg</string>
</array>
<key>NSDocumentClass</key>
<string>PVDocument</string>
</dict>
</array>
我将它添加到 plist
文件中这是行不通的。弹出窗口显示以下错误消息。
I added it to the plist
file but it does not work. A popup window shows the following error message.
无法打开文档test.jpg。 MyApp无法以JPEG图像格式打开文件
。
The document "test.jpg" could not be opened. MyApp cannot open files in the "JPEG image" format.
此外,我阅读 有 public.image
这将是我想要定义的。
Further, I read in the documentation that there is public.image
which would be what I want to define.
同时,我发现 plist
文件只包含密钥 CFBundleDocumentTypes
如果我创建一个可可应用程序,选项创建文档 - 基于应用程序。你可以澄清选项存在什么依赖关系?
Meanwhile, I found out that the plist
file only contains the key CFBundleDocumentTypes
if I create a Cocoa Application with the option "Create document-based application.". Can you please clarify what dependencies exist for the option?
推荐答案
<key>CFBundleDocumentTypes</key>
<array>
<dict>
<key>CFBundleTypeExtensions</key>
<array>
<string>png</string>
<string>jpg</string>
... add as many types as you need
</array>
... other keys
</dict>
</array>
更新:Mac OS X v10.5中不推荐使用CFBundleDocumentTypes密钥。应该使用新的关键LSItemContentTypes。这些项目是UTI字符串:
Update: The CFBundleDocumentTypes key is deprecated in Mac OS X v10.5. The new key LSItemContentTypes should be used instead. The items are UTI strings:
<key>LSItemContentTypes</key>
<array>
<string>public.png</string>
</array>
这篇关于如何在plist文件中定义统一类型标识符?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!