【发布时间】:2018-12-31 07:01:23
【问题描述】:
只是先清理一些快速项目:
- 我不想打开和/或预览文档,因为我看到一个常见的答案是指用户这样做的依赖项
- 我不想选择任何其他文件类型。我的应用特别想获取一个 powerpoint 文档,然后将其传递给 API 调用
话虽如此,我无法让我的选择器允许我打开 PPTX,如下所示:
我已采取以下措施来尝试解决此问题:
我对文件运行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 文件。
** 更新 ** 根据马特的评论,我确实将值添加到我的 plist 中,但仍然无法选择文件。
我还在 plist 和 UIDocumentPickerViewController 调用中使用 pptx 扩展进行了测试,但也没有成功。
【问题讨论】:
-
我的猜测是问题在于,虽然 you 知道
"com.microsoft.powerpoint.ppt"是扩展名为PPTX的文件的 UTI,但运行时并不知道它,并且您没有在 Info.plist 中导出该信息,因此它无法 知道它。 -
谢谢@matt。我想我之前尝试过一种变体,但我继续测试将该值添加到我的 plist 中,但没有成功。重命名 plist 和 init 调用以使用 pptx 扩展名也不起作用。
-
不要将 pptx 信息放在“文档类型”下。它需要在“Imported UTIs”下。 “文档类型”适用于您希望自己的应用列在另一个应用的“打开方式”下的情况。
-
感谢@rmaddy,能够根据您的建议让它发挥作用。
标签: ios swift uti uidocumentpickerviewcontroller