Search code examples
iosswiftutiuidocumentpickerviewcontroller

Unable to select a PowerPoint (PPTX) document with UIDocumentPickerViewController


Just to clear up a few quick items first:

  1. I do not want to open and/or preview the document, as I see a common answer referring users to a dependency for doing that
  2. I do not want to select any other file type. My app specifically wants to take a powerpoint document and then pass it to an API call

With that said, I have been unable to get my picker to allow me to open a PPTX as seen here: enter image description here

I have taken the following actions to try and resolve this:

I ran mdls -name kMDItemContentTypeTree test.pptx against the file to obtain its content type.

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" )

Which I then added to my info.plist file as seen here:

<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>

Then, I referenced this Apple site to get the UTI for powerpoint.

com.microsoft.powerpoint.​ppt

Finally, I set up my call like this:

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

But, as seen in the initial image, this does not allow me to select the file. Thus, I am hoping to find the missing piece to allow for the selection of just powerpoint files.

** UPDATE ** Based on matt's comment, I did add the value to my plist and was still unable to select the file.

enter image description here

I additionally tested using a pptx extension in the plist & UIDocumentPickerViewController call with no success either.


Solution

  • org.openxmlformats.presentationml.presentation is defined by iOS, so you do not need to include it in your imported types. The definition is imported by iOS already.

    • if you need to get your app to be available in the share sheet when a pptx file is shared, you only need to add a CFBundleDocumentTypes entry. But since you say you can only process these files, not open them, this might not be appropriate. Maybe what you want to do is write a sharing extension instead.

    • if you just want to be able to choose pptx files in UIDocumentPickerViewController, you do not need to add anything to your plist file!! Just init your picker with documentTypes:["org.openxmlformats.presentationml.presentation"]

    Finally, some comments:

    • com.microsoft.powerpoint.​ppt is the UTI for binary PowerPoint files (.ppt). For pptx, you want the openxmlformats one.

    • you do not need to claim support for, define, or add to your list of allowed UTIs for your picker any other types. The other types listed in the content type tree Spotlight attribute are the parent types of pptx. For example, if you add public.presentation to your list, you will also be able to open Keynote files. This may not be what you want.