IOS 8 open image in my app from another apps

2019-02-20 09:44发布

问题:

I did some research but seems still no luck

when I added these xml in my info.plist

<key>UTImportedTypeDeclarations</key>
    <array>
        <dict>
            <key>UTTypeConformsTo</key>
            <array>
                <string>public.data</string>
            </array>
            <key>UTTypeIdentifier</key>
            <string>my.custom.uti</string>
            <key>UTTypeDescription</key>
            <string>PDF file</string>
        </dict>
    </array>
    <key>CFBundleDocumentTypes</key>
    <array>
        <dict>
            <key>LSItemContentTypes</key>
            <array>
                <string>public.data</string>
            </array>
            <key>CFBundleTypeIconFile</key>
            <string>Icon.png</string>
            <key>CFBundleTypeRole</key>
            <string>Editor</string>
            <key>CFBundleTypeName</key>
            <string>my.custom.uti</string>
            <key>LSHandlerRank</key>
            <string>Alternate</string>
        </dict>
    </array>

and I send 3 email to myself. 1 - pdf file. 2 - png file. 3 - jpg and png file.

when i added these xmls, my app can shows in pdf and txt file, when clicked "open with..." but what I want is open with in images. anything goes wrong?? and I set UITTypeConformsTo = public.data suppose that it is a general value. So that my app can open all the formats(at least pdf and images) , but seems it dont.

I also try to copy the xml in this answer to my info.plist https://stackoverflow.com/a/11609935/1061074 still no luck

回答1:

In my app, I don't use key UTImportedTypeDeclarations. You can remove it and try with below:

<key>CFBundleDocumentTypes</key>
<array>
    <dict>
        <key>CFBundleTypeName</key>
        <string>Image</string>
        <key>LSHandlerRank</key>
        <string>Alternate</string>
        <key>LSItemContentTypes</key>
        <array>
            <string>public.image</string>
        </array>
    </dict>
    <dict>
        <key>CFBundleTypeName</key>
        <string>OpenDocument Text</string>
        <key>LSHandlerRank</key>
        <string>Alternate</string>
        <key>LSItemContentTypes</key>
        <array>
            <string>org.oasis.opendocument.text</string>
        </array>
    </dict>
    <dict>
        <key>CFBundleTypeName</key>
        <string>GIF image</string>
        <key>LSHandlerRank</key>
        <string>Alternate</string>
        <key>LSItemContentTypes</key>
        <array>
            <string>com.compuserve.gif</string>
        </array>
    </dict>
    <dict>
        <key>CFBundleTypeName</key>
        <string>PNG image</string>
        <key>LSHandlerRank</key>
        <string>Alternate</string>
        <key>LSItemContentTypes</key>
        <array>
            <string>public.png</string>
        </array>
    </dict>
    <dict>
        <key>CFBundleTypeName</key>
        <string>TIFF image</string>
        <key>LSHandlerRank</key>
        <string>Alternate</string>
        <key>LSItemContentTypes</key>
        <array>
            <string>public.tiff</string>
        </array>
    </dict>
    <dict>
        <key>CFBundleTypeName</key>
        <string>JPEG image</string>
        <key>LSHandlerRank</key>
        <string>Alternate</string>
        <key>LSItemContentTypes</key>
        <array>
            <string>public.jpeg</string>
        </array>
    </dict>
    <dict>
        <key>CFBundleTypeName</key>
        <string>Rich Text</string>
        <key>LSHandlerRank</key>
        <string>Alternate</string>
        <key>LSItemContentTypes</key>
        <array>
            <string>public.rtf</string>
            <string>com.apple.rtfd</string>
            <string>com.apple.flat-rtfd</string>
        </array>
    </dict>
    <dict>
        <key>CFBundleTypeName</key>
        <string>Text</string>
        <key>LSHandlerRank</key>
        <string>Alternate</string>
        <key>LSItemContentTypes</key>
        <array>
            <string>public.text</string>
            <string>public.plain-text</string>
            <string>public.utf8-plain-text</string>
            <string>public.utf16-external-plain-​text</string>
            <string>public.utf16-plain-text</string>
            <string>com.apple.traditional-mac-​plain-text</string>
            <string>public.source-code</string>
            <string>public.c-source</string>
            <string>public.objective-c-source</string>
            <string>public.c-plus-plus-source</string>
            <string>public.objective-c-plus-​plus-source</string>
            <string>public.c-header</string>
            <string>public.c-plus-plus-header</string>
            <string>com.sun.java-source</string>
            <string>public.script</string>
            <string>public.shell-script</string>
        </array>
    </dict>
    <dict>
        <key>CFBundleTypeName</key>
        <string>PDF</string>
        <key>LSHandlerRank</key>
        <string>Alternate</string>
        <key>LSItemContentTypes</key>
        <array>
            <string>com.adobe.pdf</string>
        </array>
    </dict>
</array>


回答2:

It all depends on how "share" button in the host app is implemented. In iOS8, there are actually two different ways to do this: (1) using CFBundleDocumentTypes in Info.plist, and (2) Application Extension. Some apps such as GMail & AVR support both (1) & (2). But Dropbox supports (2) only. That's why CFBundleDocumentTypes does not work in Dropbox anymore. Of course, things may change later.