3

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.

CodeBender
  • 35,668
  • 12
  • 125
  • 132
  • My guess is that the problem is that, although _you_ know that `"com.microsoft.powerpoint.​ppt"` is the UTI for a file with extension `PPTX`, the runtime doesn't know it, and you are not exporting that information in your _Info.plist_ so it has no _way_ of knowing it. – matt Jul 23 '18 at 18:52
  • Thanks @matt. I think I previously tried a variation of that, but I went ahead and tested adding that value to my plist with no success. Renaming the plist and init call to use the pptx extension also did not work. – CodeBender Jul 23 '18 at 18:59
  • 2
    Do not put the pptx info under "Document Types". It needs to be under "Imported UTIs". "Document Types" is for when you want your app listed under another app's "Open In". – rmaddy Jul 23 '18 at 19:45
  • Thanks @rmaddy, was able to get it working from your suggestion. – CodeBender Jul 23 '18 at 21:58

1 Answers1

4

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.

Thomas Deniau
  • 2,488
  • 1
  • 15
  • 15
  • Thanks. I only posted a subset of our functionality in the question, so a sharing extension would not be beneficial in our particular scenario. Simply passing "org.openxmlformats.presentationml.presentation" to the document picker was sufficient. – CodeBender Jul 24 '18 at 15:14
  • 1
    @Thomas I am trying to open com.microsoft.powerpoint.​ppt in document picker. But i could not select the .ppt file. please help me – Hitesh Apr 09 '20 at 12:24
  • @Hitesh please explain what's happening in detail. – Thomas Deniau Apr 10 '20 at 13:17
  • @ThomasDeniau I am trying to select .ppt file from document picker but I could not. Here I am pass below file type in the document picker. In document picker, I have contained both types of files (.ppt and .pptx) ["com.microsoft.powerpoint.​ppt","com.microsoft.powerpoint.​pptx","org.openxmlformats.presentationml.presentation"] – Hitesh Apr 10 '20 at 13:27
  • @Hitesh Are you able to fix it ?? – Balaji Ramakrishnan Apr 27 '21 at 13:25
  • @BalajiRamakrishnan I did not find yet, If I will find then add the answer – Hitesh May 04 '21 at 12:53
  • That should work. If you set the document types to ["com.microsoft.powerpoint.​ppt"] what happens? Are ppt files grayed out? You did not redefine anything in your plist did you? – Thomas Deniau May 04 '21 at 13:26