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 SwiftUI
import CoreData
@main
struct 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
Hi I am newbie to the CloudKit and have tried to convert CoreDataCloudKitDemo to work with public database after watching the wwdc20-10650. I have the following error outputs. It doesn't help much, any suggestions? Thank you.

<CKError 0x600002825770: "Partial Failure" (2/1011); "Failed to modify some records"; partial errors: {

CDFAKETag81FFFFC1-FD86-4121-B201-08A1F761B2AB:(defaultZone:defaultOwner) = <CKError 0x6000028de730: "Internal Error" (1/1000); "No authToken received for asset">

CDFAKEImageDataC8B4705B-EB7D-4F8B-A21D-A9EDB303A74E:(defaultZone:defaultOwner) = <CKError 0x6000028de430: "Internal Error" (1/1000); "No authToken received for asset">

CDFAKEPost620D3755-64F5-49A6-8793-16D8AB5F8154:(defaultZone:defaultOwner) = <CKError 0x6000028de9d0: "Internal Error" (1/1000); "No authToken received for asset">
... 2 "Batch Request Failed" CKError's omited ...

CoreDataCloudKitDemo[5308:617130] [error] error: CoreData+CloudKit: -[NSCloudKitMirroringDelegate recoverFromPartialError:forStore:inMonitor:]blockinvoke(1943): <NSCloudKitMirroringDelegate: 0x600001dacdd0>: Found unknown error as part of a partial failure: <CKError 0x6000028d1e90: "Batch Request Failed" (22/2024); "Record <CKRecordID: 0x7ff7abeb3460; recordName=CDFAKEAttachment6F83B3CB-184C-4E89-8CB3-7CCC488C05BE, zoneID=defaultZone:defaultOwner> will not be saved because of previous error in atomic zone">

Unable to initialize CloudKit schema: A Core Data error occurred.

CoreData: debug: CoreData+CloudKit: -[NSCloudKitMirroringDelegate remoteStoreDidChange:]
block_invoke(2150): <NSCloudKitMirroringDelegate: 0x600001dacdd0> - Ignoring remote change notification because it didn't change any entities tracked by persistent history: <NSSQLCore: 0x7fd3356154a0>

Error Domain=NSCocoaErrorDomain Code=134417 "Request '<NSCloudKitMirroringExportRequest: 0x600002824d20> 0F6F3A38-6A55-4900-A114-811C997A3841' was cancelled because there is already a pending request of type 'NSCloudKitMirroringExportRequest'." UserInfo={NSLocalizedFailureReason=Request '<NSCloudKitMirroringExportRequest: 0x600002824d20> 0F6F3A38-6A55-4900-A114-811C997A3841' was cancelled because there is already a pending request of type 'NSCloudKitMirroringExportRequest'.}


Just got another model working by mostly try and error. Used with CloudKit is checked, that is inside Cloud configuration's inspector

Code Block func load() {
    let defaultDirectoryURL = NSPersistentContainer.defaultDirectoryURL()
    let cloudStoreURL = defaultDirectoryURL.appendingPathComponent("Cloud.sqlite")
    let cloudStoreDescription = NSPersistentStoreDescription(url: cloudStoreURL)
    cloudStoreDescription.configuration = "Cloud"
    cloudStoreDescription.cloudKitContainerOptions =
        NSPersistentCloudKitContainerOptions(
            containerIdentifier: "iCloud.com.example.app")
    cloudStoreDescription.cloudKitContainerOptions?.databaseScope = .public
    cloudStoreDescription.setOption(true as NSNumber, forKey: NSPersistentHistoryTrackingKey)
    cloudStoreDescription.setOption(true as NSNumber, forKey: NSPersistentStoreRemoteChangeNotificationPostOptionKey)
    
    let localStoreURL = defaultDirectoryURL.appendingPathComponent("Local.sqlite")
    let localStoreDescription = NSPersistentStoreDescription(url: localStoreURL)
    localStoreDescription.configuration = "Local"
    
    persistentContainer.persistentStoreDescriptions = [ cloudStoreDescription, localStoreDescription ]
    persistentContainer.loadPersistentStores(completionHandler: { (_, error) in
        guard let error = error as NSError? else { return }
        fatalError("###\(#function): Failed to load persistent stores:\(error)")
    })
    
    persistentContainer.viewContext.mergePolicy = NSMergeByPropertyObjectTrumpMergePolicy
    persistentContainer.viewContext.transactionAuthor = appTransactionAuthorName
    persistentContainer.viewContext.automaticallyMergesChangesFromParent = true
    do {
        try persistentContainer.viewContext.setQueryGenerationFrom(.current)
    } catch {
        fatalError("###\(#function): Failed to pin viewContext to the current generation:\(error)")
    }
    
}


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