Unable to load CloudKit CoreData Store

I have a CoreData model, in a Swift Package with tests.

I can successfully run the tests, when I load the model using NSPersistentContainer, however attempting this with NSPersistentCloudKitContainer always fails in the call to loadPersistentStores(completionHandler block: @escaping (NSPersistentStoreDescription, Error?) -> Void)

The error is : [CK] BUG IN CLIENT OF CLOUDKIT: Not entitled to listen to push notifications. Please add the 'aps-connection-initiate' entitlement.

This issue is described on StackOverflow however, the accepted solution does not appear to work in my case.

I have tried adding the aps-connection-initiate key to my App Info.plist, the Test Info.plist and the SPM bundle. No change. (NB. adding this to the entitlements file just breaks auto signing).

I have enabled App entitlements for App Groups, Remote Notifications background mode, Push Notifications and iCloud CloudKit with a store identifier.

I have checked my model. All relationships have inverses. No unique constraints, etc. etc.

I am sharing a Bundle ID with a previous version of the App, that also uses CoreData+CloudKit, each version has it's own Model and container identifier, each container identifier is available in the provisioning profile.

The new version of the model has two NSPersistentStoreDescriptions, one is configured for CloudKit, the other is a local cache.

I am completely stuck, suggestions would be very welcome.

Did you end up finding a solution for this ?

It sounds like Apple enforced the entitlements usage in iOS 16 CloudKit.

You need to run your tests in Xcode : generate a Xcode project before running your SPM tests or use the target which uses your package (I guess at some point your package is added to a regular iOS/macOS target). https://forums.swift.org/t/how-can-test-targets-be-run-with-entitlement/47482/2

I believe this a Rosetta bug only affecting iOS 16. I am unable to test on and actual device since I have already updated to 17 on all of my physical devices, but I can only reproduce this on a Rosetta simulator running 16/16.4, it doesn't occur on any iOS 17, or non-rosetta 16 builds.

I also started encountering this error in the Rosetta simulator running iOS 16. Xcode 15.4. The iOS 17 simulator is not affected.

No idea how to fix it! As of now testing apps with CloudKit capability on iOS 16 simulator with Rosetta is impossible.

If anyone finds any solution or a workaround - please share it here.

Unable to load CloudKit CoreData Store
 
 
Q