CloudKit Stopped Syncing after adding new Entities

Can someone please shed some light? I have an app that uses Core Data and CloudKit, up until the last version, I was able to sync data between devices but now after I added two new Entities for some reason it stopped syncing between devices.

Here is how I did the change:

  1. Created a new Core Data container.
  2. Added the new Entities and their Attributes
  3. Tested the new Entities locally to be able to send the new schema to CloudKit.
  4. Went to CloudKit and made sure that the new Entities and Attributes were reflected on the Developent database.
  5. Deploy Schema Cahnges.
  6. Went to the Production database to make sure the new schema was deployed; and it was, both databases look the same.

Testing:

  1. Tested in the simulator and with a real device and everything syncs, even the new Entities.
  2. If I download the app from the App Store on two different devices they do NOT sync.

Based on the procedure I'm describing above, is there any important step I may have missed when doing the migration?

I'm not sure if this is related to the syncing issue but after testing a few times, I no longer can turn the iCloud on, I get the following message when I try to turn iCloud Sync On.

CoreData: error: CoreData+CloudKit: -[NSCloudKitMirroringDelegate resetAfterError:andKeepContainer:]: <NSCloudKitMirroringDelegate: 0x282c488c0> - resetting internal state after error: Error Domain=NSCocoaErrorDomain Code=134410 "CloudKit setup failed because there is another instance of this persistent store actively syncing with CloudKit in this process." UserInfo={NSURL=file:///var/mobile/Containers/Data/Application/73F19BC7-4538-4098-85C7-484B36192CF3/Library/Application%20Support/CoreDataContainer.sqlite, NSLocalizedFailureReason=CloudKit setup failed because there is another instance of this persistent store actively syncing with CloudKit in this process., NSUnderlyingException=Illegal attempt to register a second handler for activity identifier com.apple.coredata.cloudkit.activity.setup.8D4C04F6-8040-445A-9447-E5646484521}

Any idea of what could be wrong and preventing the devices from syncing? Any idea or suggestion is welcome.

Thanks

I've exactly your issue. I've released an app update recently with new Entities and some users (not all the users) are encountering an issue with app sync. They have also tried to uninstall and install the app again without results. The really strange thing is that on each device, when data is downloaded from iCloud, two different versions of the library are restored, exactly the one that was previously on that particular device.

Your issue sounds more like a schema issue. Did you recently add or removed Entities or attributes to your Core Data model? If you did, you must deploy schema changes in the CloudKit console, by going to CloudKit Console -> Development Database -> Deploy Schema Changes.

If you haven't made any changes to your Core Data model, make sure that all of your Entities and attributes are present in the Development database under Schema -> Record Types. If you're missing Entities or attributes, go to your app and enter some data for the missing entities or attributes, this will create them in the development database; make sure to have CloudKit on in your app when you enter the data. I hope it makes sense.

I've had this problem before and I'm currently experiencing this now.

My issue is that I neglected to update the Schema indexes for each new Entity to add (what seems to be necessary):

  • modifiedTimestamp - Queryable
  • modifiedTimestamp - Sortable
  • recordName - Queryable

Once I have added these indexes to each new Entity, my sync began working again between devices and iCloud.

Although recently, making the same mistake, my macOS instance no longer synced and I'm still trying to solve that problem.

CloudKit Stopped Syncing after adding new Entities
 
 
Q