【问题标题】:How to import custom file extension to an iOS project on XCode?如何在 XCode 上将自定义文件扩展名导入 iOS 项目?
【发布时间】:2020-09-28 03:32:34
【问题描述】:

我尝试将新的自定义文件扩展名“.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文件是灰色的:

【问题讨论】:

    标签: ios objective-c swift xcode plist


    【解决方案1】:

    您的 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 部分为您的特定类型输入一个条目。

    【讨论】:

    • 还是没有运气。我改用“public.data”。它允许打开任何文件类型。但是还是不知道具体的.uuu文件怎么打开。
    • 您是否将UTExportedTypeDeclarations 键添加到Info.plist?
    • 是的,我添加了 UTExportedTypeDeclarations
    • 好的 - 应该可以,更新您的转储以显示最新的 Info.plist 的 CFBundleDocumentTypes 和 UTExportedTypeDeclarations。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多