ios - 为什么我的 iOS 应用程序没有出现在其他应用程序的 "Open in"对话框中?

标签 ios file-handling uti launch-services

我正在尝试实现允许我的 iOS 应用程序显示在其他应用程序的“打开方式”列表中的注册过程(如 Apple's Document Interaction Programming Topics 中所述)。我希望我的应用能够处理来自任何提供标准音频文件格式(MP3、AIFF、WAV 等)的应用的音频。

据我所知,我需要做的就是将 CFBundleDocumentTypes 键和相关的子数据添加到我的应用程序的 Info.plist 中。这是我输入的内容(通过 Xcode 4 的文档类型编辑器):

<key>CFBundleDocumentTypes</key>
<array>
    <dict>
        <key>CFBundleTypeIconFiles</key>
        <array>
            <string>scrubbulator-icon</string>
        </array>
        <key>CFBundleTypeName</key>
        <string>Audio</string>
        <key>LSHandlerRank</key>
        <string>Alternative</string>
        <key>LSItemContentTypes</key>
        <array>
        <string>public.mp3</string>
        </array>
    </dict>
</array>

添加此代码不会在应用程序的“打开方式”菜单中显示我的应用程序(我正在 iPhone 上测试,使用 Dropbox 中的 MP3 作为文件源。应用程序 AudioMemos 和 Evernote 都显示为 MP3 Dropbox 中的文件,所以我知道支持该格式)。有什么明显的我做错了,或者我需要实现其他什么吗?

(注意:我没有在我的 Info.plist 中设置 UTExportedTypeDeclarations 项,因为我知道这些仅对自定义 UTI 是必需的。因为我使用的是系统 UTI,我认为它应该这是必要的,但如果我错了,请纠正我。)

编辑

我添加了以下导出类型 UTI,但没有成功:

<key>UTExportedTypeDeclarations</key>
<array>
    <dict>
        <key>UTTypeConformsTo</key>
        <array>
        <string>kUTTypeMP3</string>
        </array>
        <key>UTTypeDescription</key>
        <string>Audio file</string>
        <key>UTTypeIdentifier</key>
        <string>kUTTypeMP3</string>
        <key>UTTypeTagSpecification</key>
        <dict>
        <key>public.filename-extension</key>
        <array>
            <string>mp3</string>
        </array>
        </dict>
    </dict>
</array>

最佳答案

对于所有标准文件格式:

<key>CFBundleDocumentTypes</key>
<array>
    <dict>
        <key>CFBundleTypeName</key>
        <string>Unknown File</string>
        <key>LSHandlerRank</key>
        <string>Alternate</string>
        <key>LSItemContentTypes</key>
        <array>
            <string>public.calendar-event</string>
            <string>public.database</string>
            <string>public.executable</string>
            <string>public.data</string>
            <string>public.content </string>
            <string>public.item</string>
        </array>
    </dict>
    <dict>
        <key>CFBundleTypeName</key>
        <string>Video</string>
        <key>LSHandlerRank</key>
        <string>Alternate</string>
        <key>LSItemContentTypes</key>
        <array>
            <string>public.video</string>
        </array>
    </dict>
    <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>Web Archive</string>
        <key>LSHandlerRank</key>
        <string>Alternate</string>
        <key>LSItemContentTypes</key>
        <array>
            <string>com.apple.webarchive</string>
        </array>
    </dict>
    <dict>
        <key>CFBundleTypeName</key>
        <string>iWork Keynote</string>
        <key>LSHandlerRank</key>
        <string>Alternate</string>
        <key>LSItemContentTypes</key>
        <array>
            <string>com.apple.keynote.key</string>
            <string>com.apple.iwork.keynote.key</string>
            <string>com.apple.iwork.keynote.kth</string>
        </array>
    </dict>
    <dict>
        <key>CFBundleTypeName</key>
        <string>iWork Numbers</string>
        <key>LSHandlerRank</key>
        <string>Alternate</string>
        <key>LSItemContentTypes</key>
        <array>
            <string>com.apple.numbers.numbers</string>
            <string>com.apple.iwork.numbers.numbers</string>
            <string>com.apple.iwork.numbers.template</string>
        </array>
    </dict>
    <dict>
        <key>CFBundleTypeName</key>
        <string>iWork Pages</string>
        <key>LSHandlerRank</key>
        <string>Alternate</string>
        <key>LSItemContentTypes</key>
        <array>
            <string>com.apple.page.pages</string>
            <string>com.apple.iwork.pages.pages</string>
            <string>com.apple.iwork.pages.template</string>
        </array>
    </dict>
    <dict>
        <key>CFBundleTypeName</key>
        <string>OpenDocument Spreadsheet</string>
        <key>LSHandlerRank</key>
        <string>Alternate</string>
        <key>LSItemContentTypes</key>
        <array>
            <string>org.oasis.opendocument.spreadsheet</string>
        </array>
    </dict>
    <dict>
        <key>CFBundleTypeName</key>
        <string>OpenDocument Presentation</string>
        <key>LSHandlerRank</key>
        <string>Alternate</string>
        <key>LSItemContentTypes</key>
        <array>
            <string>org.oasis.opendocument.presentation</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>Folder</string>
        <key>LSHandlerRank</key>
        <string>Alternate</string>
        <key>LSItemContentTypes</key>
        <array>
            <string>public.folder</string>
        </array>
    </dict>

    <dict>
        <key>CFBundleTypeName</key>
        <string>Audio</string>
        <key>LSHandlerRank</key>
        <string>Alternate</string>
        <key>LSItemContentTypes</key>
        <array>
            <string>public.audio</string>
            <string>public.mp3</string>
            <string>public.mpeg-4-audio</string>
            <string>com.apple.protected-​mpeg-4-audio</string>
            <string>public.aifc-audio</string>
            <string>com.apple.coreaudio-​format</string>
            <string>public.aiff-audio</string>
        </array>
    </dict>

    <dict>
        <key>CFBundleTypeName</key>
        <string>Movie</string>
        <key>LSHandlerRank</key>
        <string>Alternate</string>
        <key>LSItemContentTypes</key>
        <array>
            <string>public.movie</string>
            <string>public.3gpp2</string>
            <string>public.3gpp</string>
            <string>public.mpeg</string>
            <string>com.apple.quicktime-movie</string>
            <string>public.mpeg-4</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>XML</string>
        <key>LSHandlerRank</key>
        <string>Alternate</string>
        <key>LSItemContentTypes</key>
        <array>
            <string>public.xml</string>
        </array>
    </dict>
    <dict>
        <key>CFBundleTypeName</key>
        <string>HTML</string>
        <key>LSHandlerRank</key>
        <string>Alternate</string>
        <key>LSItemContentTypes</key>
        <array>
            <string>public.html</string>
            <string>public.xhtml</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>CFBundleTypeExtensions</key>
        <array>
            <string>zip</string>
            <string>zipx</string>
        </array>
        <key>CFBundleTypeName</key>
        <string>Zip archive</string>
        <key>LSHandlerRank</key>
        <string>Alternate</string>
        <key>LSItemContentTypes</key>
        <array>
            <string>public.zip-archive</string>
            <string>public.archive</string>
            <string>com.pkware.zip-archive</string>
            <string>com.pkware.zipx-archive</string>
        </array>
    </dict>
    <dict>
        <key>CFBundleTypeExtensions</key>
        <array>
            <string>rar</string>
            <string>RAR</string>
        </array>
        <key>CFBundleTypeName</key>
        <string>Rar archive</string>
        <key>LSHandlerRank</key>
        <string>Alternate</string>
        <key>LSItemContentTypes</key>
        <array>
            <string>com.rarlab.rar-archive</string>
            <string>public.archive</string>
        </array>
    </dict>
    <dict>
        <key>CFBundleTypeExtensions</key>
        <array>
            <string>7z</string>
            <string>7Z</string>
        </array>
        <key>CFBundleTypeName</key>
        <string>7z archive</string>
        <key>LSHandlerRank</key>
        <string>Alternate</string>
        <key>LSItemContentTypes</key>
        <array>
            <string>org.7-zip.7-zip-archive</string>
            <string>public.archive</string>
        </array>
    </dict>
    <dict>
        <key>CFBundleTypeName</key>
        <string>Waveform audio</string>
        <key>LSHandlerRank</key>
        <string>Alternate</string>
        <key>LSItemContentTypes</key>
        <array>
            <string>com.microsoft.waveform-​audio</string>
        </array>
    </dict>
    <dict>
        <key>CFBundleTypeName</key>
        <string>Windows icon image</string>
        <key>LSHandlerRank</key>
        <string>Alternate</string>
        <key>LSItemContentTypes</key>
        <array>
            <string>com.microsoft.ico</string>
            <string>com.apple.icns</string>
        </array>
    </dict>
    <dict>
        <key>CFBundleTypeName</key>
        <string>Windows bitmap image</string>
        <key>LSHandlerRank</key>
        <string>Alternate</string>
        <key>LSItemContentTypes</key>
        <array>
            <string>com.microsoft.bmp</string>
        </array>
    </dict>
    <dict>
        <key>CFBundleTypeName</key>
        <string>Microsoft PowerPoint</string>
        <key>LSHandlerRank</key>
        <string>Alternate</string>
        <key>LSItemContentTypes</key>
        <array>
            <string>com.microsoft.powerpoint.​ppt</string>
            <string>org.openxmlformats.presentationml.presentation</string>
        </array>
    </dict>
    <dict>
        <key>CFBundleTypeName</key>
        <string>Microsoft Excel</string>
        <key>LSHandlerRank</key>
        <string>Alternate</string>
        <key>LSItemContentTypes</key>
        <array>
            <string>org.openxmlformats.spreadsheetml.sheet</string>
            <string>com.microsoft.excel.xls</string>
        </array>
    </dict>
    <dict>
        <key>CFBundleTypeName</key>
        <string>Microsoft Word</string>
        <key>LSHandlerRank</key>
        <string>Alternate</string>
        <key>LSItemContentTypes</key>
        <array>
            <string>com.microsoft.word.doc</string>
            <string>com.microsoft.word.wordml</string>
            <string>org.openxmlformats.wordprocessingml.document</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>

关于ios - 为什么我的 iOS 应用程序没有出现在其他应用程序的 "Open in"对话框中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9266079/

相关文章:

c 文件处理 : unable to write after 25 y?

cocoa - Cocoa (AppKit) 是否提供标准 UTI 常量?

objective-c - 如何从文件路径获取文档 UTI?

macos - 检索可以在给定 URL 处打开文件的所有应用程序包标识符

ios - 扩展 UILocalNotification

iOS 从 Google + OAuth 数据中解析用户信息

ios - 在 UITextField 中键入时,将给定字符串的每个字符替换为键入的字符

c - FprintF 从链接列表到文件

c++ - g++ 9.2.1 (Linux) 导致段错误,但 Windows 上的代码块不会

ios - 基于数组对 NSFetchedResultsController 结果进行排序?