0

I have just started experimenting with Catalyst. My app is a document browser based app.

The stock MacOS Finder dialog is indeed launched when the appropriate button is clicked. The main app window completely disappears when the Finder dialog appears, unless I choose in the IB for the document browser view controller to appear in "Automatic" mode.

Cancelling the operation indeed brings back the main window.

However, selecting a file will yield a blank screen and no results. A little debugging revealed that none of the file selection functions is being called, and I have implemented all of them:

func documentBrowser(_ controller: UIDocumentBrowserViewController, didPickDocumentURLs documentURLs: [URL]) {...}

func documentBrowser(_ controller: UIDocumentBrowserViewController, didImportDocumentAt sourceURL: URL, toDestinationURL destinationURL: URL) {...}

func documentBrowser(_ controller: UIDocumentBrowserViewController, failedToImportDocumentAt documentURL: URL, error: Error?) {...}

Is there another function or handle used in Catalyst? I found nothing in the documentation.

EDIT: I should clarify that I manipulated the app to present the DocumentViewController before the DocumentBrowserViewController, although Apple requires that the DocumentBrowserViewController is the initial view controller. I did it by changing the app delegate:

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {

...

// Set the documentViewController to appear first
    self.window = UIWindow(frame: UIScreen.main.bounds)

    let storyboard = UIStoryboard(name: "Main", bundle: nil)

    let initialViewController = storyboard.instantiateViewController(withIdentifier: "main")

    self.window?.rootViewController = initialViewController
    self.window?.makeKeyAndVisible()

    return true
}

Taking this out still doesn't change anything. And a default project created from the document browser template does seem to work. What could prevent these methods from being called?

DrMickeyLauer
  • 4,455
  • 3
  • 31
  • 67
Ron Regev
  • 459
  • 2
  • 18

1 Answers1

1

I would suggest to implement func documentBrowser(_ controller: UIDocumentBrowserViewController, didPickDocumentsAt documentURLs: [URL]) as well

xnth97
  • 36
  • 3
  • This was indeed the missing function. My next problem is not related to this question - the viewController is not on the view hierarchy after loading the file, despite making it the root view controller, and using makeKeyAndVisible. Any ideas? – Ron Regev Oct 20 '19 at 08:40
  • I suspect it may be related to your showing DocumentViewController prior to DocumentBrowserViewController, since from my own experience I guess MacCatalyst uses DocumentBrowserViewController as some entry point. Sorry that I can't provide much input on this problem – xnth97 Oct 21 '19 at 18:14
  • Found the answer - in the iPad version I switched view controllers by calling makeKeyAndVisible, in order to clear all traces of previous view controllers. In MacCatalyst this can only work once, in the app delegate. After that, when you want to switch to a new view controller, you have to use the present method. – Ron Regev Oct 29 '19 at 07:00