【发布时间】:2011-09-05 15:55:32
【问题描述】:
我的应用程序使用以下NSApplicationDelegate 函数。
- (void)application:(NSApplication*)sender openFiles:(NSArray*)filenames;
我想使用此功能使用户能够将图像文件拖放到 Dock 中的应用程序图标上。
如何在我的plist 文件中定义某些文件类型以将它们限制为图像?我发现结构必须看起来像这样。
// 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 文件中,但它不起作用。弹出窗口显示以下错误消息。
无法打开文档“test.jpg”。 MyApp 无法打开文件 “JPEG 图像”格式。
此外,我读到 in the documentation 有 public.image 这将是我想要定义的。
同时,我发现plist 文件仅包含密钥CFBundleDocumentTypes,如果我使用“创建基于文档的应用程序”选项创建一个 Cocoa 应用程序。您能否澄清一下该选项存在哪些依赖项?
【问题讨论】:
标签: objective-c drag-and-drop mime-types uti