简体   繁体   中英

Why can't I register my iOS application to handle the image file type?

I have a problem registering image file types to my application. I tried adding the code below to my plist but nothing happens.

<key>CFBundleDocumentTypes</key>
    <array>
        <dict>
            <key>CFBundleTypeName</key>
            <string>Scary Bug Document</string>
            <key>LSHandlerRank</key>
            <string>Alternate</string>
            <key>CFBundleTypeRole</key>
            <string>None</string>
            <key>LSItemContentTypes</key>
            <array>
                <string>public.image</string>
            </array>
        </dict>
    </array>

I noticed that I can register for other file types, such as text (changing the public.image to public.text ) but it just won't work with images (the "Open In .." menu is not showing my app).

What could be causing this, and how could I fix it?

It is now possible to open images from the mail app in iOS 7, it's just somewhat convoluted:

Tap and hold the image. Tap on Quick Look so the image goes fullscreen. Tap the image to show the top toolbar. Tap the open in button at the top right. Scroll the list to the left to find your app.

Be sure to set up your bundle document types for the image types you are interested in.

Dimitri Bouniol response that it works in iOS 7 via quick look is correct. The following additions to my in info.plist below are how I got it to work for my app. Still have not figured out how to get share in photos or camera roll to work.

  <key>CFBundleDocumentTypes</key>
    <array>
        <dict>
            <key>CFBundleTypeExtensions</key>
            <array>
                <string>myapp image</string>
            </array>
            <key>CFBundleTypeName</key>
            <string>public.png</string>
            <key>CFBundleTypeRole</key>
            <string>Editor</string>
            <key>LSHandlerRank</key>
            <string>Alternate</string>
            <key>LSItemContentTypes</key>
            <array>
                <string>public.png</string>
                <string>public.jpeg</string>
            </array>
        </dict>
    </array>
    <key>UTImportedTypeDeclarations</key>
    <array>
        <dict>
            <key>UTTypeConformsTo</key>
            <array>
                <string>public.image</string>
            </array>
            <key>UTTypeIdentifier</key>
            <string>public.png</string>
            <key>UTTypeTagSpecification</key>
            <dict>
                <key>com.apple.ostype</key>
                <string>PNG</string>
                <key>public.filename-extension</key>
                <array>
                    <string>png</string>
                </array>
                <key>public.mime-type</key>
                <string>image/png</string>
            </dict>
        </dict>
        <dict>
            <key>UTTypeIdentifier</key>
            <string>public.jpeg</string>
            <key>UTTypeReferenceURL</key>
            <string>http://www.w3.org/Graphics/JPEG/</string>
            <key>UTTypeDescription</key>
            <string>JPEG image</string>
            <key>UTTypeIconFile</key>
            <string>public.jpeg.icns</string>
            <key>UTTypeConformsTo</key>
            <array>
                <string>public.image</string>
                <string>public.data</string>
            </array>
            <key>UTTypeTagSpecification</key>
            <dict>
                <key>com.apple.ostype</key>
                <string>JPEG</string>
                <key>public.filename-extension</key>
                <array>
                    <string>jpeg</string>
                    <string>jpg</string>
                </array>
                <key>public.mime-type</key>
                <string>image/jpeg</string>
            </dict>
        </dict>
    </array>

Try:

<key>CFBundleDocumentTypes</key>
    <array>
        <dict>
            <key>CFBundleTypeName</key>
            <string>Scary Bug Document</string>
            <key>LSHandlerRank</key>
            <string>Alternate</string>
            <key>CFBundleTypeRole</key>
            <string>None</string>
            <key>LSItemContentTypes</key>
            <array>
                <string>public.png</string>
                <string>public.jpg</string>
            </array>
        </dict>
    </array>

Also, see this other answer on StackOverflow

After doing a bit of research it seems that is not possible to register the app for images. Thanks for your answers.

public.image是一种抽象类型,请尝试注册public.png或public.jpeg等

OS will not allow you to open images in your app. I also tried myself a lot of permutation & combination, and confirmed from a few more posts in Apple Support.

Per Apple's documentation, "to add the document type do the following:

  • Click on the disclosure button for Document Types to open the document types.
  • In the “Types” section fill in the UTI for the new type.
  • For the key value type: CFBundleTypeRole.
  • For the value type: Editor.
  • For the key value type: LSHandlerRank.
  • For the value type: Owner."

This works for me using public.image as the UTI.

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