Maybe this is fully clear to all by now, but as I encountered the same problem but did not see a solution spelled out for point B.2 (opening documents from the finder), and as I found benspratling4's solution for point B.1 interesting (as it avoids having to set the root vc back to the document browser vc when closing the document), I thought I would share code snippets with a possible solution to both issues.
Point B.1 (following benspratling4)
Once you instantiate the document vc, do not present it directly like in iOS, but open the document first.
let doc = Document(fileURL: documentURL)
doc.open(completionHandler: { success in
if success {
self.present(documentViewController, animated: true)
}
})
This will also allow you to have the document browser show up automatically when dismissing the document programmatically later.
Point B.2
Maybe the issue is that the default implementation of the application(app:open:options:) in AppDelegate, which works for iOS, does not work for Catalyst, as it tries to reveal (and possibly import) the document. I see that if you do not reveal the document in the document browser, then it opens without issues:
func application(_ app: UIApplication, open inputURL: URL, options: [UIApplication.OpenURLOptionsKey : Any] = [:]) - Bool {
guard inputURL.isFileURL else {
return false
}
guard let documentBrowserViewController = window?.rootViewController as? DocumentBrowserViewController else {
return false
}
documentBrowserViewController.presentDocument(at: inputURL)
}
(where "presentDocument" is the method that includes the first code snipper above - I just wrote down the Catalyst part, you may of course have to implement iOS/Catalyst with #if blocks).
Hope it helps.
Topic:
UI Frameworks
SubTopic:
UIKit
Tags: