Facing issues with document-based app on macOS Big Sur 11.1

Facing new behavior and issues with my Mac Catalyst document-based app on macOS Big Sur 11.1 run on Intel processor.

A. Getting some new "Focus system enabled" and many "Focus system disabled" messages. Does anyone know what these messages are about?

B. But even worse after getting the following message: "Did present bridged document browser". Actually did not see that before. Does anyone know what this message is about?
  1. Error: The first "Did present Bridget document browser" message appears when presenting the UIDocumentBrowserViewController, which maybe makes sense. After selecting and loading the document and transitioning to the document controller, the document content appears in the view. All fine so far. But then immediately the same message appears again and the view with the document disappears (without viewWillDisappear or anything) and the UIDocumentBrowserViewController is shown again. Hence it is not possible to open and update an existing document anymore! The creation of a new document is still possible and works fine.

  2. Error: When opening a document from the Finder (outside the app), a "Save" window appears, which never did before. If you click "Save", it tells you that the file already exists and if you want to replace it. If you click "Replace", the document import fails with the alert message that the document can not be copied, because an item with the same name already exists. Hence it's not possible to open and update an existing document using the same name anymore!

Except for macOS Big Sur 11.1 the app runs fine on all platforms and versions: macOS 10.15.7, iPadOS 14.3, iOS 14.3. Using Xcode 12.3. 
Answered by JaydenIrwin in 659970022
Exact same issue here on Big Sur 11.2 as well.

(As a workaround, when I want to open a document VC on catalyst, I set the rootViewController to the document VC instead of presenting it on top.)
Getting the same behaviour here, it's basically non-functional on Catalyst. Did anyone actually test this before it shipped?
Accepted Answer
Exact same issue here on Big Sur 11.2 as well.

(As a workaround, when I want to open a document VC on catalyst, I set the rootViewController to the document VC instead of presenting it on top.)
@JaydenIrwin: many thanks for your hint. It works! The transition animation is not that elegant, but ok.

Had first a bit problem with using the navigationController. It works only this way:
UIApplication.shared.windows.first?.rootViewController = documentVC.navigationController

To make the dismiss of the documentVC working, I have to set the rootViewController back to the documentBrowserVC.
I worked around problem B 1 by not presenting my document vc until after the document successfully opens.
so my code is
  • create document

  • create document view controller

  • open document

  • in completion block, if successful open, present document view controller on top of UIDocumentBrowserViewController

I tried presenting a "spinner" view controller I created on top of the browser, but when I do the browser dismisses itself ( dismiss(... is getting called and I'm not calling it in my code) out from under the presented view controller. This seems to be related to why the repeated showing of the browser happens - something to do with the browser getting dismissed out from under the document view controller.
re: B 2, I think maybe possibly you're calling the "import" method on the document browser view controller in response to your external open request? I think the import method on the document browser vc is for moving a file into the directory alongside the other url in the call. i.e. it doesn't mean "open me". I'm only using import when "openInPlace" is false, or when the user selects a file in a file format that I support converting from but not saving in. i.e. I have my native file format I'll call "s" and there is a public standard other apps create I'll call "x". I have "x" listed as a document format in my app, and as an imported type, and when the user selects one, I convert it into a temp file in format "s", then use "import" to bring it into the dir next to the original file, this causes the system to prompt the user to save the new file, which is a little unexpected nicety which is probably the right thing to do. But I wouldn't use "import" when the original document is in a format I would save in or the openInPlace was true.
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.

Code Block
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:

Code Block
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.

Re A: It seems that this is the rather buggy focus system on Catalyst. Basically that log entry means that your app technically has lost the focus – though there should no reason for it. However, certain drag and drop functions or SwiftUI buttons cease to function then, which makes part of your UI unresponsive.

Facing issues with document-based app on macOS Big Sur 11.1
 
 
Q