Xcode 4 Document Types and Exported UTIs

孤人 提交于 2020-01-05 09:34:56

问题


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.

My latest try looks like this: (Copied the entry made from Xcode in the 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.

Sandro


回答1:


I think the role and the file extension are missing.

If you want to specify a file extension, you need to add 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:

<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>



回答2:


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

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

I think the other properties speak for themselves.




回答3:


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.



来源:https://stackoverflow.com/questions/5408029/xcode-4-document-types-and-exported-utis

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!