Core Data + CloudKit crash on startup only in production

Hi,

My macOS app's production build is crashing on start with an unhelpful crashdump. In the console, the only error in the Console is

BUG IN CLIENT OF CLOUDKIT: Not entitled to listen to push notifications. Please add the 'com.apple.private.aps-connection-initiate' entitlement.

Adding this entitlement to my entitlements.plist breaks the app entirely (Unsatisfied entitlements). Here is how I'm loading my persisten store:

    lazy var persistentContainer: NSPersistentCloudKitContainer = {
        let container = NSPersistentCloudKitContainer(name: "ChatModel")
        guard let description = container.persistentStoreDescriptions.first else {
            fatalError("###\(#function): Failed to retrieve a persistent store description.")
        }
        if(UserDefaults.standard.bool(forKey: StoredPreferenceKey.iCloudSync)){
            description.cloudKitContainerOptions = NSPersistentCloudKitContainerOptions(containerIdentifier: "iCloud.XXXXX")
        } else {
            description.cloudKitContainerOptions = nil
        }
        description.setOption(true as NSNumber, forKey: NSPersistentHistoryTrackingKey)
        description.setOption(true as NSNumber, forKey: NSPersistentStoreRemoteChangeNotificationPostOptionKey)
/* #if DEBUG
        do {
            // Use the container to initialize the development schema.
            try container.initializeCloudKitSchema(options: [])
        } catch {
            // Handle any errors.
        }
#endif */
        container.loadPersistentStores { description, error in
            if let error = error {
                fatalError("Unable to load persistent stores: \(error)")
            }
        }
        container.viewContext.automaticallyMergesChangesFromParent = true
        
        return container
    }()

I've set up Core Data + CloudKit following the official docs, screenshots attached.

The app works fine in development mode. I'm using Xcode 14.3, and I've tried with Xcode 14.2 too.

Any idea ? Web results (i.e. only two relevant threads) bring no answer.

Is this a standard app? Or something else?

Would you be able to install the CloudKit logging profile, reproduce the issue, take a sysdiagnose, and submit a bug through Feedback Assistant on CloudKit?

Yes, the same thing happened to me today. I forgot to add the "Capabilities" to each of my targets. I think you need to enable the "Background Modes" one, with 'Remote Notifications' and 'Background Fetch' checked in addition to just iCloud.

Core Data + CloudKit crash on startup only in production
 
 
Q