如何在 plist 文件中定义统一类型标识符?

发布于 2024-12-03 04:29:08 字数 1514 浏览 1 评论 0原文

我的应用程序使用以下 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

风吹过旳痕迹 2024-12-10 04:29:08
    <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>

更新:CFBundleDocumentTypes 密钥在 Mac OS X v10.5 中已弃用。应改用新密钥 LSItemContentTypes。这些项目是 UTI 字符串:

<key>LSItemContentTypes</key>
<array>
    <string>public.png</string>
</array>
    <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>

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>
鹿港巷口少年归 2024-12-10 04:29:08

如果您的文档类型是常见类型,您可以使用 UTI's
关于 UTI

If your document types are common types, you could use UTI's
About UTI's

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文