如何在 plist 文件中定义统一类型标识符?
我的应用程序使用以下 NSApplicationDelegate 函数。
- (void)application:(NSApplication*)sender openFiles:(NSArray*)filenames;
我想使用此功能使用户能够将图像文件拖放到扩展坞中的应用程序图标上。
如何在 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 图像”格式。
此外,我阅读了 在文档中有 public.image
这就是我想要定义的。
同时,我发现如果我使用“创建基于文档的应用程序”选项创建 Cocoa 应用程序,则 plist
文件仅包含键 CFBundleDocumentTypes
。您能否澄清该选项存在哪些依赖关系?
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.
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>
I added it to the plist
file but it does not work. A popup window shows the following error message.
The document "test.jpg" could not be opened. MyApp cannot open files
in the "JPEG image" format.
Further, I read in the documentation that there is public.image
which would be what I want to define.
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
更新:CFBundleDocumentTypes 密钥在 Mac OS X v10.5 中已弃用。应改用新密钥 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:
如果您的文档类型是常见类型,您可以使用
UTI's
关于 UTI
If your document types are common types, you could use
UTI's
About UTI's