简体   繁体   中英

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. I don't know where I did wrong, I checked the plist for several times but no luck.

Here the info.plist content of the file extension below:

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

在此处输入图片说明

Your Info.plist content is very strange. Look you have a key of CFBundleDocumentTypes which has as value an array. In this array again you have key CFBundleDocumentTypes and its content is not correct. 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. You probably also need an entry in the UTExportedTypeDeclarations section for your specific type.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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