Can a UIDocumentPickerViewController show the contents of my app's Documents folder?

I am working on an app that is successfully saving and retrieving crossword files (writing them out in JSON) but currently only works with hardcoded file names.

I now want my user to be able to select files from the Documents folder, and I would like the UI to look a) good, and b) follow Apple's guidelines.

I tried using the UIDocumentPickerViewController, but this article seems to imply that it only works with files that are external to the sandbox.

With the code below, I just end up seeing a Downloads folder.
Code Block
let documentPicker = UIDocumentPickerViewController(documentTypes: ["public.item", "public.data"], in: .im)
documentPicker.delegate = self
documentPicker.modalPresentationStyle = .formSheet
documentPicker.directoryURL = FileManager.default.urls(for: .documentDirectory, in: .userDomainMasks[0]
print(documentPicker.directoryURL) // yup, this is right
self.present(documentPicker, animated: true)

What's the right way to let the user see the contents of their Documents folder, so they can pick a file from it? I could read the contents and put them in a table view, but the UIDocumentPickerView's view looks (of course) very polished.

Thanks for any help!

Accepted Reply

I figured it out, I needed an entry in Info.plist.

Replies

I figured it out, I needed an entry in Info.plist.
Presumably this was UISupportsDocumentBrowser?

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@apple.com"
Yes ... and no :-(

What I want is to a) create a folder, CrosswordRewind, inside the sandbox's Documents folder, and b) put up a gorgeous UI to show me that folders contents (with UIDocumentsPickerViewController).

I've accomplished a), and the reason I said "yes ... and no" is because I can see CrosswordRewind on the simulator, not on an iPad

The folder got created on the iPad (I can see it thanks to the Devices window), but Files is showing me 3 folders -- Minecraft, Exploring EDU, and Recovered Files.

I have 3 theories:
  1. I'm using the wrong class. The docs say a UIDocumentPickerViewController is a "view controller that provides access to documents or destinations outside [my emphasis] your app's sandbox." They don't say anything about inside.

  2. I've misconfigured UIDocumentPickerViewController somehow, so it won't show me (on the iPad) my current Document folder.

  3. What I'm saving isn't actually a UIDocument -- maybe that's illegal (but just on the iPad)