title: UIDocumentBrowser doesn’t work on iPads while works fine on a simulator [iOS, Swift]
body: <h3>I am learning about how to build a <code>document-based</code> app in iOS.</h3>
  <p>I followed Apple's official example (<a href="https://developer.apple.com/documentation/uikit/view_controllers/building_a_document_browser-based_app#overview" rel="nofollow noreferrer">https://developer.apple.com/documentation/uikit/view_controllers/building_a_document_browser-based_app#overview</a>) and tried to revise it to display a PDF viewer.</p>
  <p>I modified the original sample code to create the following code. It works totally fine with any simulators on my Macbook Pro (2020). However, when I tested with iPads (i.e., iPad Mini &amp; iPad Pro: new generations), I cannot open PDF files.</p>
  <p>I identified that the following code is not working:
  <code>let doc = PDFDocument(url: documentURL)</code>.
  The URL seems to be appropriately obtained. <code>doc</code> remains to be <code>nil</code> when testing with iPads, while appropriately obtained when testing with simulators.</p>
  <p>I would really appreciate it if you could let me know what is wrong with my code.</p>
  <h4>DocumentBrowserController.swift</h4>
  <pre><code>import UIKit
  import os.log
  import PDFKit
  
  /// - Tag: DocumentBrowserViewController
  class DocumentBrowserViewController: UIDocumentBrowserViewController, UIDocumentBrowserViewControllerDelegate {
      
      /// - Tag: viewDidLoad
      override func viewDidLoad() {
          super.viewDidLoad()
          delegate = self
          
          allowsDocumentCreation = true
          allowsPickingMultipleItems = false
      }
      
       //MARK: - UIDocumentBrowserViewControllerDelegate
      
      // UIDocumentBrowserViewController is telling us to open a selected a document.
      func documentBrowser(_ controller: UIDocumentBrowserViewController, didPickDocumentsAt documentURLs: [URL]) {
          if let url = documentURLs.first {
              presentDocument(at: url)
          }
      }
      
      // MARK: - Document Presentation
     var transitionController: UIDocumentBrowserTransitionController?
      
      func presentDocument(at documentURL: URL) {
          let storyBoard = UIStoryboard(name: &quot;Main&quot;, bundle: nil)
  
          // Load the document's view controller from the storyboard.
          let instantiatedNavController = storyBoard.instantiateViewController(withIdentifier: &quot;DocNavController&quot;)
          guard let docNavController = instantiatedNavController as? UINavigationController else { fatalError() }
          guard let documentViewController = docNavController.topViewController as? TextDocumentViewController else { fatalError() }
          
  //        // Load the document view.
  //        documentViewController.loadViewIfNeeded()
  //
          // In order to get a proper animation when opening and closing documents, the DocumentViewController needs a custom view controller
          // transition. The `UIDocumentBrowserViewController` provides a `transitionController`, which takes care of the zoom animation. Therefore, the
          // `UIDocumentBrowserViewController` is registered as the `transitioningDelegate` of the `DocumentViewController`. Next, obtain the
          // transitionController, and store it for later (see `animationController(forPresented:presenting:source:)` and
          // `animationController(forDismissed:)`).
          docNavController.transitioningDelegate = self
          
          // Get the transition controller.
          transitionController = transitionController(forDocumentAt: documentURL)
          
          let doc = PDFDocument(url: documentURL)
  
          transitionController!.targetView = documentViewController.pdfView
    
          
          // Present this document (and it's navigation controller) as full screen.
          docNavController.modalPresentationStyle = .fullScreen
  
          // Set and open the document.
          documentViewController.document = doc
          os_log(&quot;==&gt; Document Opened&quot;, log: .default, type: .debug)
          self.present(docNavController, animated: true, completion: nil)
      }
      
  }
  
  extension DocumentBrowserViewController: UIViewControllerTransitioningDelegate {
      
      func animationController(forPresented presented: UIViewController,
                               presenting: UIViewController,
                               source: UIViewController) -&gt; UIViewControllerAnimatedTransitioning? {
          // Since the `UIDocumentBrowserViewController` has been set up to be the transitioning delegate of `DocumentViewController` instances (see
          // implementation of `presentDocument(at:)`), it is being asked for a transition controller.
          // Therefore, return the transition controller, that previously was obtained from the `UIDocumentBrowserViewController` when a
          // `DocumentViewController` instance was presented.
          return transitionController
      }
      
      func animationController(forDismissed dismissed: UIViewController) -&gt; UIViewControllerAnimatedTransitioning? {
          // The same zoom transition is needed when closing documents and returning to the `UIDocumentBrowserViewController`, which is why the the
          // existing transition controller is returned here as well.
          return transitionController
      }
      
  }
  </code></pre>
  <h3>TextDocumentViewController.swift</h3>
  <p>(I just post this here too, although this code does not seem to be the problem)</p>
  <pre><code>/*
   See LICENSE folder for this sample’s licensing information.
   
   Abstract:
   A view controller for displaying and editing documents.
   */
  
  import UIKit
  import os.log
  import PDFKit
  
  var currentPage = 0
  
  /// - Tag: textDocumentViewController
  class TextDocumentViewController: UIViewController, PDFDocumentDelegate, PDFViewDelegate {
      
      @IBOutlet weak var pdfView: PDFView!
      @IBOutlet weak var doneButton: UIBarButtonItem!
      
      private var keyboardAppearObserver: Any?
      private var keyboardDisappearObserver: Any?
      
      var document: PDFDocument! {
          didSet {
              document.delegate = self
          }
      }
      
      override init(nibName nibNameOrNil: String?, bundle nibBundleOrNil: Bundle?) {
          super.init(nibName: nibNameOrNil, bundle: nibBundleOrNil)
          //        setupNotifications()
      }
      
      required init?(coder aDecoder: NSCoder) {
          super.init(coder: aDecoder)
          //        setupNotifications()
      }
      
      override func viewDidLoad() {
          super.viewDidLoad()
          
          pdfView.delegate = self
          doneButton.isEnabled = false
          
          if #available(iOS 13.0, *) {
              /** When turned on, this changes the rendering scale of the text to match the standard text scaling
               and preserves the original font point sizes when the contents of the text view are copied to the pasteboard.
               Apps that show a lot of text content, such as a text viewer or editor, should turn this on and use the standard text scaling.
               
               For more information, refer to the WWDC 2019 video on session 227 &quot;Font Management and Text Scaling&quot;
               https://developer.apple.com/videos/play/wwdc2019/227/
               (from around 30 minutes in, and to the end)
               */
          }
      }
      
      override func viewWillAppear(_ animated: Bool) {
          super.viewWillAppear(animated)
          
          pdfView.document = document!
          pdfView.autoScales = true
          pdfView.displayMode  = .singlePage
          pdfView.displayDirection = .horizontal
          pdfView.displaysPageBreaks = true
          pdfView.pageBreakMargins = UIEdgeInsets(top: 10, left: 20, bottom: 10, right: 20)
          pdfView.usePageViewController(true)                   
      }
      
      override func viewDidDisappear(_ animated: Bool) {
          super.viewDidDisappear(animated)
          
      }
      
      
      
  }
  </code></pre>
  <h4>* I simplified the code trying to illustrate the problem clearly (2020/10/27)</h4>