如何将自定义文件扩展名导入XCode上的iOS项目?

问题描述

我试图将新的自定义文件扩展名“ .uuu”添加到我的iOS应用程序中,添加的.PDF和.ZIP格式有效,但.uuu格式无效。我不知道我做错了什么,我检查了几次plist但没有运气。

以下是文件扩展名的info.plist内容

<key>CFBundleDocumentTypes</key>
<array>
    <dict>
        <key>CFBundleDocumentTypes</key>
        <array>
            <dict>
                <key>CFBundleTypeExtensions</key>
                <array>
                    <string>pdf</string>
                </array>
                <key>CFBundleTypeName</key>
                <string>pdf</string>
                <key>LSHandlerRank</key>
                <string>None</string>
            </dict>
        </array>
        <key>CFBundleTypeIconFiles</key>
        <array/>
        <key>CFBundleTypeName</key>
        <string>PDFReader</string>
        <key>LSItemContentTypes</key>
        <array>
            <string>com.adobe.pdf</string>
        </array>
    </dict>

    <dict>
        <key>CFBundleDocumentTypes</key>
        <array>
            <dict>
                <key>CFBundleTypeExtensions</key>
                <array>
                    <string>zip</string>
                </array>
                <key>CFBundleTypeName</key>
                <string>zip</string>
                <key>LSHandlerRank</key>
                <string>None</string>
            </dict>
        </array>
        <key>CFBundleTypeIconFiles</key>
        <array/>
        <key>CFBundleTypeName</key>
        <string>Zip</string>
        <key>LSItemContentTypes</key>
        <array>
            <string>public.zip-archive</string>
        </array>
    </dict>

    <dict>
        <key>CFBundleDocumentTypes</key>
        <array>
            <dict>
                <key>CFBundleTypeExtensions</key>
                <array>
                    <string>uuu</string>
                </array>
                <key>CFBundleTypeName</key>
                <string>uuu</string>
                <key>LSHandlerRank</key>
                <string>None</string>
            </dict>
        </array>
        <key>CFBundleTypeIconFiles</key>
        <array/>
        <key>CFBundleTypeName</key>
        <string>UUU</string>
        <key>LSItemContentTypes</key>
        <array>
            <string>public.uuuFiles</string>
        </array>
    </dict>

</array>

浏览器中的uuu文件为灰色:

enter image description here

解决方法

您的Info.plist内容非常奇怪。看起来您有一个CFBundleDocumentTypes键,其键值为数组。再次在此数组 中,您有密钥CFBundleDocumentTypes,其内容不正确。有些元素在里面,有些在外面。

您应该做一些不同的事情。我会修复第一个,然后其他人也照做,然后看看效果如何。

<key>CFBundleDocumentTypes</key>
<array>
    <dict>
      <key>CFBundleTypeExtensions</key>
      <array>
        <string>pdf</string>
      </array>
      <key>CFBundleTypeName</key>
      <string>pdf</string>
      <key>LSHandlerRank</key>
      <string>None</string>
      <key>CFBundleTypeIconFiles</key>
      <array/>
      <key>CFBundleTypeName</key>
      <string>PDFReader</string>
      <key>LSItemContentTypes</key>
        <array>
            <string>com.adobe.pdf</string>
        </array>
    </dict>

作为参考,请创建一个新的基于文档的应用程序并查看其Info.plist。您可能还需要在UTExportedTypeDeclarations部分中输入您的特定类型。