代码之家  ›  专栏  ›  技术社区  ›  CodeBender

无法使用UIDocumentPickerViewController选择PowerPoint(PPTX)文档

  •  1
  • CodeBender  · 技术社区  · 8 年前

    先来整理一下:

    1. 我不想打开和/或预览文档,因为我看到了一个常见的答案,它将用户引向执行此操作的依赖项
    2. 我不想选择任何其他文件类型。我的应用程序特别希望获取一个powerpoint文档,然后将其传递给一个API调用

    尽管如此,我还是无法让选择器允许我打开PPTX,如图所示: enter image description here

    我已采取以下措施试图解决此问题:

    我跑了 mdls -name kMDItemContentTypeTree test.pptx 获取其内容类型。

    kMDItemContentTypeTree = (
        "org.openxmlformats.presentationml.presentation",
        "public.data",
        "public.composite-content",
        "public.archive",
        "public.item",
        "org.openxmlformats.presentationml.presentation",
        "org.openxmlformats.openxml",
        "public.zip-archive",
        "public.presentation",
        "public.content",
        "com.pkware.zip-archive" )
    

    然后我将其添加到info.plist文件中,如下所示:

    <dict>
        <key>LSItemContentTypes</key>
        <array>
            <string>org.openxmlformats.presentationml.presentation</string>
            <string>public.data</string>
            <string>public.composite-content</string>
            <string>public.archive</string>
            <string>public.item</string>
            <string>org.openxmlformats.presentationml.presentation</string>
            <string>org.openxmlformats.openxml</string>
            <string>public.zip-archive</string>
            <string>public.presentation</string>
            <string>public.content</string>
            <string>com.pkware.zip-archive</string>
        </array>
        <key>CFBundleTypeName</key>
        <string>PPTX</string>
        <key>LSHandlerRank</key>
        <string>Alternate</string>
    </dict>
    

    然后,我引用了这个 Apple site 获取powerpoint的UTI。

    com.microsoft.powerpoint.ppt网站

    最后,我把电话设置成这样:

    let powerpointType = "com.microsoft.powerpoint.​ppt"
    let documentPicker = UIDocumentPickerViewController(documentTypes: [powerpointType], 
                                                        in: .import)
    

    但是,正如在初始图像中看到的,这不允许我选择文件。因此,我希望找到丢失的部分,以便只选择powerpoint文件。

    **更新** 根据matt的评论,我确实将值添加到plist中,但仍然无法选择文件。

    enter image description here

    我还用 pptx 扩展的plist& UIDocumentPickerViewController 打电话也没有成功。

    1 回复  |  直到 8 年前
        1
  •  1
  •   Thomas Deniau    8 年前

    org.openxmlformats.presentationml.presentation 是由ios定义的,因此不需要将其包含在导入的类型中。定义已由iOS导入。

    • 如果在共享pptx文件时需要使应用程序在共享表中可用,则只需添加cfbundledocumenttypes条目。但既然你说你只能处理这些文件,而不能打开它们,这可能不合适也许你想做的是写一个共享扩展。

    • 如果您只想选择pptx文件 UIDocumentPickerViewController ,不需要向plist文件添加任何内容!!只要用 documentTypes:["org.openxmlformats.presentationml.presentation"]

    最后,一些评论:

    • com.microsoft.powerpoint.​ppt 是二进制PowerPoint文件(.ppt)的UTI对于pptx,您需要openxmlformats。

    • 您不需要为选择器的任何其他类型声明对允许的utis的支持、定义或添加到列表中。“内容类型树聚光灯”属性中列出的其他类型是pptx的父类型例如,如果将public.presentation添加到列表中,则还可以打开注释记号文件这可能不是你想要的。

    推荐文章