0

I want to initialize an UIDocumentPickerViewController from a framework. But, the files (.pdf) are shown as grayed out in the document picker when using below code in framework. The code works fine when UIDocumentPickerViewController is initialized in the main app target. This is what I use.

    let documentPicker = UIDocumentPickerViewController(forOpeningContentTypes: [.pdf])
    documentPicker.delegate = self
    present(documentPicker, animated: true, completion: nil)
Dhanesh KM
  • 449
  • 2
  • 7
  • 18

2 Answers2

0

As you are having UIDocumentPickerViewController in the framework, so better way to do this is to use custom UIViewController and implement all the delegates of UIDocumentPickerViewController in that view controller. Then in your main app, you can inherit that custom UIViewController and call parent APIs to load UIDocumentPickerViewController.

Ankit Thakur
  • 4,739
  • 1
  • 19
  • 35
0

The issue in my case was, I was trying to present UIDocumentPickerViewController from window.rootViewController as I don't have access to a UIViewController from my main target. I created a UIViewController in my framework and presented UIDocumentPickerViewController from there and it worked. But, still I am not sure what is the difference in presenting UIDocumentPickerViewController from a window.rootViewController vs from a real UIViewController object. Well, both are UIViewControllers

Dhanesh KM
  • 449
  • 2
  • 7
  • 18