3

I'm building an app using a UIDocumentBrowserViewController. All was working fine (locations and documents appeared, and were creatable, selectable)

All of a sudden, the document browser is showing up empty. No locations, no documents…

enter image description here

Prior to today, the browser was empty in the simulator, but worked fine on a device. Now the problem his "migrated" its way to my iPad. I assume this is a beta issue, but would be grateful to know if anyone else suffering from the same has managed to find a fix / workaround?

Tried…

  • Clean build
  • Deleting module cache / derived data
  • Deleting / re-installing the app
  • Restarting Xcode
  • Restarting iPad
  • Re-installing Xcode
  • Rebooting Mac

I'm beginning to think I'm imagining that it was working in the past!

Xcode 9.0 beta 4 (9M189t)


Update

I just found that using

let dbvc = UIDocumentBrowserViewController(forOpeningFilesWithContentTypes:[kUTTypePlainText as String])

instead of my custom UTI works. And then reverting to my own UTI again still works.

Ashley Mills
  • 50,474
  • 16
  • 129
  • 160

3 Answers3

3

I had the same issue. The workaround I found was to NOT delete the "images" dictionary from the generated info.plist. I had made changes to the info.plist and at some point replaced it with another that didn't have the "images" in the plist. This is the section you need:

<dict>
        <key>CFBundleTypeIconFiles</key>
        <array/>
        <key>CFBundleTypeName</key>
        <string>Images</string>
        <key>CFBundleTypeRole</key>
        <string>Viewer</string>
        <key>LSHandlerRank</key>
        <string>Alternate</string>
        <key>LSItemContentTypes</key>
        <array>
            <string>public.image</string>
        </array>
    </dict>

Putting this back in (or not taking it out) eliminated the problem. Hope this helps.

Archimage
  • 31
  • 1
  • I came across that on earlier… a lot of the issues I had initially were with the custom UTI. I thought I had that all fixed, but looks like it's still a problem. – Ashley Mills Aug 03 '17 at 12:50
1

I had this problem until I add to info.plist one missing parameter in the list of supported document types:

Document Types > Item > Handler Rank (string) Alternate

enter image description here

Krishna Raj Salim
  • 7,331
  • 5
  • 34
  • 66
Marek Manduch
  • 2,303
  • 1
  • 19
  • 22
0

Are there no files in app's document directory?

if app's document directory is empty, it is not visible in UIDocumentBrowserViewController.

try

 override func viewDidLoad() {
    super.viewDidLoad()

    let fm = FileManager.default
    let documentsPath = NSSearchPathForDirectoriesInDomains(.documentDirectory, .userDomainMask, true).first!

    let filePath = documentsPath + "/myfile.txt"
    if !fm.fileExists(atPath: filePath) {
        fm.createFile(atPath: filePath, contents: nil, attributes: [:])
    }
}
hoge
  • 1