Hello,
Not sure if you still have the same issue. I had the same problem, but today after several trials I found out that it seems to be solved by simply naming the configurations, i.e.:
let modelConfigForNoCloudSync = ModelConfiguration("local", schema: modelNotForCloudSyncing, cloudKitDatabase: .none) let modelConfigForCloudSync = ModelConfiguration("synced", schema: modelsForCloudSyncing, cloudKitDatabase: .automatic)
This seems to be enough to get rid of all the 'duplicate stores' issues, and the data syncs as intended.
Post
Replies
Boosts
Views
Activity
[EDIT] If anybody is interested, this is the simplest way to reproduce the issue using the Xcode template: (1) Create a new project in Xcode 13.0. (2) Choose iOS -> Document App. (3) Choose Interface: Storyboard and create the project (for simplicity let’s use “MyApp” as Product Name). (4) Build and install MyApp on a device running iOS 15.0 or 15.0.1 with iCloud Drive enabled. (5) Leave the default setting for Document Storage (i.e. iCloud Drive) in Settings -> MyApp. (6) Create a text file with any content and save it with extension “exampletext” (i.e. the imported type identifier used by the app template - let’s call the file “test.exampletext”). (7) Send an email to an inbox accessible from the device with test.exampletext as attachment. (8) Open Mail on the device, long-press on test.exampletext and share it to MyApp. If a folder “MyApp” exists in iCloud Drive, it will be renamed to “MyApp 2”; a new “MyApp” folder will be created and test.exampletext will be saved in the new folder. Sharing again test.exampletext from the mail to MyApp will create another “MyApp” folder and rename the previous one; an arbitrary number of “MyApp n” folders can be created in this way, each including one copy of the document. I submitted a bug report using the Feedback Assistant, hopefully it will be fixed...
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.