Given a document-based app (MyApp) using DocumentGroup:
If MyApp is not open, or it is open with the Document Browser displayed, and a file compatible with MyApp is tapped in the Files app, the tapped document opens as expected in MyApp.
If MyApp is open and displaying a document, then tapping a compatible document in the Files app switches to MyApp, but fails to display the tapped document, and logs the following error:
[Presentation] Attempt to present <SwiftUI.UIKitNavigationController: 0x11c87dc00> on <SwiftUI.DocumentBrowserViewController: 0x129018a00> (from <SwiftUI.DocumentBrowserViewController: 0x129018a00>) whose view is not in the window hierarchy.
The problem is easily demonstrated by creating a new project from the Document App template in Xcode and running it in the simulator
Run the app and create a new document (Untitled)
Close Untitled and create another document (Untitled 2)
Close Untitled 2
Open Untitled
Switch to the Files app, navigate to the MyApp folder and tap on Untitled 2
The error above will be shown in Xcode.
Does anyone have any insight into how to solve this?
Thank you
Post
Replies
Boosts
Views
Activity
The UIDocument documentation saysTo get autosaving capabilities for your documents, you must implement change tracking. Typically you do this by using an NSUndoManager object (assigned to undoManager property) to register changes or by calling the updateChangeCount: method every time the user makes a change; UIKit then automatically determines whether there are unsaved changes and returns the proper value from hasUnsavedChanges.I have a UIDocument based app where I call updateChangeCount(.done) to indicate the document has changed. However, contentsForType is only called after a 15 second delay. This seems rather long to me.Is there a way to increase the rate at which UIDocument responds to updateChangeCount? Or am I missing something?