简体   繁体   English

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

[英]How to import custom file extension to an iOS project on XCode?

I have tried to add the new customized file extension ".uuu" into my iOS application, the .PDF and .ZIP formats I added are working, but .uuu format doesn't work.我尝试将新的自定义文件扩展名“.uuu”添加到我的 iOS 应用程序中,我添加的 .PDF 和 .ZIP 格式可以使用,但 .uuu 格式不起作用。 I don't know where I did wrong, I checked the plist for several times but no luck.我不知道我哪里做错了,我检查了 plist 好几次,但没有运气。

Here the info.plist content of the file extension below:这里文件扩展名的 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>

The uuu file is gray in the browser: uuu 文件在浏览器中是灰色的:

在此处输入图片说明

Your Info.plist content is very strange.您的 Info.plist 内容很奇怪。 Look you have a key of CFBundleDocumentTypes which has as value an array.看你有一个CFBundleDocumentTypes的键,它有一个数组作为值。 In this array again you have key CFBundleDocumentTypes and its content is not correct.在这个数组中你有关键的CFBundleDocumentTypes并且它的内容不正确。 Some elements are inside and some outside.有些元素在里面,有些元素在外面。

You should do it a bit differently.你应该做一些不同的事情。 I will fix up the first one and then you do the others the same and see how it goes.我会修复第一个,然后你做其他相同的,看看它是怎么回事。

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

For a good reference create a new document based app and look at its Info.plist.创建一个新的基于文档的应用程序并查看其 Info.plist 以获得良好的参考。 You probably also need an entry in the UTExportedTypeDeclarations section for your specific type.您可能还需要在UTExportedTypeDeclarations部分中为您的特定类型添加一个条目。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM