Ios 无法使用UIDocumentPickerViewController选择PowerPoint(PPTX)文档
只需先清理几个快速项目:Ios 无法使用UIDocumentPickerViewController选择PowerPoint(PPTX)文档,ios,swift,uti,uidocumentpickerviewcontroller,Ios,Swift,Uti,Uidocumentpickerviewcontroller,只需先清理几个快速项目: 我不想打开和/或预览文档,因为我看到了一个常见的答案,它将用户引向依赖项 我不想选择任何其他文件类型。我的应用程序特别希望获取powerpoint文档,然后将其传递给API调用 尽管如此,我无法让我的选择器允许我打开PPTX,如下所示: 我已采取以下行动试图解决此问题: 我对该文件运行了mdls-name kMDItemContentTypeTree test.pptx,以获取其内容类型 kMDItemContentTypeTree = ( "org.open
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>
但是,如初始图像所示,这不允许我选择文件。因此,我希望找到缺失的部分,以便只选择powerpoint文件
**更新**
根据matt的评论,我确实在plist中添加了值,但仍然无法选择该文件
我在plist&
UIDocumentPickerViewController
调用中使用pptx
扩展进行了额外测试,但也没有成功。org.openxmlformats.presentationml.presentation
由iOS定义,因此您不需要将其包含在导入的类型中。该定义已由iOS导入
- 如果在共享pptx文件时需要使应用程序在共享表中可用,则只需添加CbundleDocumentTypes条目。但是,因为您说您只能处理这些文件,而不能打开它们,所以这可能不合适。也许你想做的是写一个共享扩展
- 如果您只想在
中选择pptx文件,则无需向plist文件添加任何内容!!只需使用UIDocumentPickerViewController
documentTypes:[“org.openxmlformats.presentationml.presentation”]
是二进制PowerPoint文件(.ppt)的UTI。对于pptx,您需要openxmlformatscom.microsoft.powerpoint。ppt
- 您不需要为选择器的任何其他类型声明支持、定义或添加到允许的UTI列表中。“内容类型树聚光灯”属性中列出的其他类型是pptx的父类型。例如,如果将public.presentation添加到列表中,还可以打开注释记号文件。这可能不是你想要的
PPTX
的文件的UTI,运行时不知道它,并且您没有在Info.plist中导出该信息,因此它无法知道它。谢谢@matt。我想我以前尝试过这种方法的一种变体,但我继续尝试将这种价值添加到我的plist中,但没有成功。重命名plist和init调用以使用pptx扩展名也不起作用。请不要将pptx信息放在“文档类型”下。它需要在“进口UTI”下。“文档类型”用于当您希望您的应用程序列在另一个应用程序的“打开位置”下时。谢谢@rmaddy,能够根据您的建议使其正常工作。谢谢。在这个问题中,我只发布了我们功能的一个子集,所以共享扩展在我们的特定场景中是没有好处的。只需将“org.openxmlformats.presentationml.presentation”传递给文档选择器就足够了。@Thomas我正在尝试打开com.microsoft.powerpoint。文档选择器中的ppt。但我无法选择.ppt文件。请帮忙me@Hitesh请详细解释发生了什么。@ThomasDeniau我正试图从文档选择器中选择.ppt文件,但我无法选择。在这里,我在文档选择器中传递下面的文件类型。在文档选择器中,我包含了两种类型的文件(.ppt和.pptx)[“com.microsoft.powerpoint”。ppt、com.microsoft.powerpoint。pptx“,”org.openxmlformats.presentationml.presentation“]@Hitesh您能修复它吗??
let powerpointType = "com.microsoft.powerpoint.ppt"
let documentPicker = UIDocumentPickerViewController(documentTypes: [powerpointType],
in: .import)