Xcode 4 文档类型和导出的 UTI

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/5408029/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-14 20:37:52  来源:igfitidea点击:

Xcode 4 Document Types and Exported UTIs

iphonexcodexcode4uti

提问by Sandro Meier

I have an other problem with Xcode 4. I really like the new IDE but there are a few things I didn't get to work yet. One thing is to register Document Types with Xcode 4. I tried it with the old way through the plist file, but it didn't work. (Means I couldn't open a file with my app) But I don't now how to set it up with the interface of Xcode 4.

我在使用 Xcode 4 时还有一个问题。我真的很喜欢新的 IDE,但还有一些东西我还没有开始工作。一件事是用 Xcode 4 注册文档类型。我通过 plist 文件用旧的方式尝试过它,但它没有用。(意味着我无法使用我的应用程序打开文件)但我现在不知道如何使用 Xcode 4 的界面进行设置。

My latest try looks like this: (Copied the entry made from Xcode in the info.plist)

我最近的尝试是这样的:(复制了 Xcode 在 info.plist 中所做的条目)

<key>UTExportedTypeDeclarations</key>
<array>
    <dict>
        <key>UTTypeConformsTo</key>
        <array>
            <string>public.plain-text</string>
        </array>
        <key>UTTypeDescription</key>
        <string>Configuration File</string>
        <key>UTTypeIdentifier</key>
        <string>com.myname.projec.iws</string>
    </dict>
</array>

and:

和:

<key>CFBundleDocumentTypes</key>
<array>
    <dict>
        <key>CFBundleTypeIconFiles</key>
        <array>
            <string>AnIcon-320</string>
        </array>
        <key>CFBundleTypeName</key>
        <string>Config File</string>
        <key>LSItemContentTypes</key>
        <array>
            <string>com.myname.projec.iws</string>
        </array>
    </dict>
</array>

This does not work. The file in Mail doesn't have the option to open with my app.

这不起作用。邮件中的文件没有使用我的应用程序打开的选项。

Does anyone have a working example with Xcode 4 or a tutorial how to do it. I don't have any further Idea how to get it work.

有没有人有 Xcode 4 的工作示例或如何做的教程。我没有任何进一步的想法如何让它工作。

Sandro

桑德罗

回答by FKDev

I think the role and the file extension are missing.

我认为缺少角色和文件扩展名。

If you want to specify a file extension, you need to add UTTypeTagSpecification:

如果要指定文件扩展名,则需要添加UTTypeTagSpecification

    <key>UTExportedTypeDeclarations</key>

<array>

    <dict>
        <key>UTTypeConformsTo</key>
        <array>
            <string>public.text</string>
        </array>
        <key>UTTypeDescription</key>
        <string>my document type</string>
        <key>UTTypeIdentifier</key>
        <string>com.mycompany.myfiletypename</string>
        <key>UTTypeTagSpecification</key>
        <dict>
            <key>public.filename-extension</key>
            <array>
                <string>iws</string>
            </array>
        </dict>
    </dict>

For the role, you need to add CFBundleTypeRole:

对于角色,您需要添加CFBundleTypeRole

<key>CFBundleDocumentTypes</key>
<array>
    <dict>
        <key>CFBundleTypeName</key>
        <string>My file</string>
        <key>CFBundleTypeIconFiles</key>
        <array>
            <string>document-320.png</string>
            <string>document-64.png</string>
        </array>
        <key>LSHandlerRank</key>
        <string>Alternate</string>
        <key>CFBundleTypeRole</key>
        <string>Viewer</string>
        <key>LSItemContentTypes</key>
        <array>
            <string>com.mycompany.myfiletypename</string>

        </array>
    </dict>
</array>

回答by Nick Kusters

You can edit the equivalent of your 'com.mycompany.myfiletypename' by setting "Document Types" => "Item 0" => "Document OS Types" => "Item 0".

您可以通过设置“文档类型”=>“项目0”=>“文档操作系统类型”=>“项目0”来编辑“com.mycompany.myfiletypename”的等效项。

The default value is "????" which you can change to "com.mycompany.myfiletypename".

默认值为“????” 您可以将其更改为“com.mycompany.myfiletypename”。

I think the other properties speak for themselves.

我认为其他属性不言自明。

回答by iGeoCacher

I just looked at my old .plist file and cut and pasted the keys and values into the new one in Xcode 4 project that had been imported from an Xcode3 version. It apparently "loses" some of the info in the .plist for UTI's when it comes over. However, when I pasted the missing keys/values back in from .plist made with Xcode3, the new values worked AND they appear in the GUI so you can now "browse" the GUI and see what goes where. Kind of reverse engineering the GUI but it works.

我只是查看了旧的 .plist 文件,然后将键和值剪切并粘贴到 Xcode 4 项目中的新文件中,该项目是从 Xcode3 版本导入的。当它出现时,它显然“丢失”了 UTI 的 .plist 中的一些信息。但是,当我从 Xcode3 制作的 .plist 中将丢失的键/值粘贴回时,新值起作用并且它们出现在 GUI 中,因此您现在可以“浏览”GUI 并查看哪里去了。对 GUI 进行逆向工程,但它有效。