NSCloudKitMirroringExportRequest issues

I'm attempting to create a Swift/SwiftUI app that will run on iOS/iPadOS that uses CloudKit to syncronize data between devices. I have created the App in Xcode.


In the Apps Signing & Capabilities tab, I have:

- Ensured that the Bundle Identifier is valid

- Added the iCloud capability

- Created the Container and checked it

- Validated that the Container was created in the CloudKit Dashbaord

- Added the Backgrouind Modes capability

- Checked the Remote notifications option


I have modified/validated AppDelegate.swift:

- Validated that it is using NSPersistentCloudKitContainer

- Added container.viewContext.automaticallyMergesChangesFromParent to true

- Added container.viewContext.mergePolicy to NSMergeByPropertyObjectTrumpMergePolicy


When I load the App, I get a series of errors reported related to CloudKit NSCloudKitMirroringExportRequest. These errors are shown below. I am able to create records, but can see they are only stored locally and do not get synced to the CloudKit Dashboard - interestingly enough, the schema has been created in CloudKit Dashboard - so I know some level of connection has been made.


I appreciate any insight that someone can give me to resolve this and allow my data to sync properly.


CoreData: CloudKit: CoreData+CloudKit: -[NSCloudKitMirroringDelegate _scheduleAutomatedExportWithLabel:activity:completionHandler:]_block_invoke(2174): <NSCloudKitMirroringDelegate: 0x600003ef0c60> - Finished automatic export - ExportActivity - with result: <NSCloudKitMirroringResult: 0x60000096cc40> success: 0 madeChanges: 0 error: Error Domain=NSCocoaErrorDomain Code=134417 "Request '<NSCloudKitMirroringExportRequest: 0x6000007545a0> B79831CF-9C04-4BB0-90B7-974EB38D2A25' was cancelled because there is already a pending request of type 'NSCloudKitMirroringExportRequest'." UserInfo={NSLocalizedFailureReason=Request '<NSCloudKitMirroringExportRequest: 0x6000007545a0> B79831CF-9C04-4BB0-90B7-974EB38D2A25' was cancelled because there is already a pending request of type 'NSCloudKitMirroringExportRequest'.}

CoreData: warning: CoreData+CloudKit: -[NSCloudKitMirroringDelegate finishedAutomatedRequestWithResult:](2119): Finished request '<NSCloudKitMirroringExportRequest: 0x6000007545a0> B79831CF-9C04-4BB0-90B7-974EB38D2A25' with result: <NSCloudKitMirroringResult: 0x60000096cc40> success: 0 madeChanges: 0 error: Error Domain=NSCocoaErrorDomain Code=134417 "Request '<NSCloudKitMirroringExportRequest: 0x6000007545a0> B79831CF-9C04-4BB0-90B7-974EB38D2A25' was cancelled because there is already a pending request of type 'NSCloudKitMirroringExportRequest'." UserInfo={NSLocalizedFailureReason=Request '<NSCloudKitMirroringExportRequest: 0x6000007545a0> B79831CF-9C04-4BB0-90B7-974EB38D2A25' was cancelled because there is already a pending request of type 'NSCloudKitMirroringExportRequest'.}

CoreData: CloudKit: CoreData+CloudKit: -[NSCloudKitMirroringDelegate _enqueueRequest:]_block_invoke(714): <NSCloudKitMirroringDelegate: 0x600003ef0c60>: enqueuing request: <NSCloudKitMirroringImportRequest: 0x6000007a7450> D59C4B33-4075-4A43-AEF0-88EDD466D644

CoreData: warning: CoreData+CloudKit: -[NSCloudKitMirroringDelegate _enqueueRequest:]_block_invoke_2(724): Failed to enqueue request: <NSCloudKitMirroringImportRequest: 0x6000007a7450> D59C4B33-4075-4A43-AEF0-88EDD466D644

Error Domain=NSCocoaErrorDomain Code=134417 "Request '<NSCloudKitMirroringImportRequest: 0x6000007a7450> D59C4B33-4075-4A43-AEF0-88EDD466D644' was cancelled because there is already a pending request of type 'NSCloudKitMirroringImportRequest'." UserInfo={NSLocalizedFailureReason=Request '<NSCloudKitMirroringImportRequest: 0x6000007a7450> D59C4B33-4075-4A43-AEF0-88EDD466D644' was cancelled because there is already a pending request of type 'NSCloudKitMirroringImportRequest'.}

CoreData: CloudKit: CoreData+CloudKit: -[NSCloudKitMirroringDelegate _scheduleAutomatedImportWithLabel:activity:completionHandler:]_block_invoke(2150): <NSCloudKitMirroringDelegate: 0x600003ef0c60> - Finished automatic import - ImportActivity - with result: <NSCloudKitMirroringResult: 0x60000096f0c0> success: 0 madeChanges: 0 error: Error Domain=NSCocoaErrorDomain Code=134417 "Request '<NSCloudKitMirroringImportRequest: 0x6000007a7450> D59C4B33-4075-4A43-AEF0-88EDD466D644' was cancelled because there is already a pending request of type 'NSCloudKitMirroringImportRequest'." UserInfo={NSLocalizedFailureReason=Request '<NSCloudKitMirroringImportRequest: 0x6000007a7450> D59C4B33-4075-4A43-AEF0-88EDD466D644' was cancelled because there is already a pending request of type 'NSCloudKitMirroringImportRequest'.}

CoreData: warning: CoreData+CloudKit: -[NSCloudKitMirroringDelegate finishedAutomatedRequestWithResult:](2119): Finished request '<NSCloudKitMirroringImportRequest: 0x6000007a7450> D59C4B33-4075-4A43-AEF0-88EDD466D644' with result: <NSCloudKitMirroringResult: 0x60000096f0c0> success: 0 madeChanges: 0 error: Error Domain=NSCocoaErrorDomain Code=134417 "Request '<NSCloudKitMirroringImportRequest: 0x6000007a7450> D59C4B33-4075-4A43-AEF0-88EDD466D644' was cancelled because there is already a pending request of type 'NSCloudKitMirroringImportRequest'." UserInfo={NSLocalizedFailureReason=Request '<NSCloudKitMirroringImportRequest: 0x6000007a7450> D59C4B33-4075-4A43-AEF0-88EDD466D644' was cancelled because there is already a pending request of type 'NSCloudKitMirroringImportRequest'.}

I have the same issue

I have same issue and I'm not using SwiftUI. Not sure about the pending request issue. Sometimes I hate these types of errors

I have the same problem. But the only thing that differ is that I am writing a macOS app. Does anyone had similar issue?

I am also having the same issue in macOS app.

I'm having the same issue, anyone managed to fix it yet?

I have the same issue
I am also having same issue not using SwiftUI. Simple swift app with CoreData and CloudKit auto syncing option turn on.

<NSCloudKitMirroringResult: 0x600000268fa0> success: 0 madeChanges: 0 error: Error Domain=NSCocoaErrorDomain Code=134417 "Request '<NSCloudKitMirroringImportRequest: 0x600000cc10e0> 1A57C80D-0BAE-4E9A-BF8C-41F695ECE8A1' was cancelled because there is already a pending request of type 'NSCloudKitMirroringImportRequest'." UserInfo={NSLocalizedFailureReason=Request '<NSCloudKitMirroringImportRequest: 0x600000cc10e0> 1A57C80D-0BAE-4E9A-BF8C-41F695ECE8A1' was cancelled because there is already a pending request of type 'NSCloudKitMirroringImportRequest'.}
I'll make a guess you are implementing your App struct as if it were a class and accidentally creating a new instance of NSPersistentCloudKitContainer every time SwiftUI recreates the struct.

You could access the persistent container lazy property through a @UIApplicationDelegateDelegateAdaptor so it is only created once.

Code Block import SwiftUIimport CoreData@mainstruct MasterDetailApp: App {	@UIApplicationDelegateAdaptor(AppDelegate.self) var appDelegate				var body: some Scene {				WindowGroup {						ContentView().environment(\.managedObjectContext, appDelegate.persistentContainer.viewContext)				}		}}

Same issue here with using
Code Block databaseScope = .public 

Did in fact treat the App struct like a class like @malc was mentioning but even migrating my CoreDataStack to a singleton did not solve this
I have the same issue any update ?
Same issues as rest of thread. Please reply if you have any updates.

FYI this thread- https://developer.apple.com/forums/thread/134096
seems to involve a similar issue.
Update: My Core Data model is now mirrored in the CloudKit schema. It started working once I removed Configurations from the model and stuck with the default. Remains to be seen whether records will save both locally and to CloudKit but at least schema is showing up now.

As a side note, I still receive many of the same console errors as before regarding failed requests and "no auth token for asset"
I have the same issue, Has anyone solved it?
NSCloudKitMirroringExportRequest issues
 
 
Q