Error: Failed to sync user keys in simulator

Hi, I'm getting an error recently

share error details <CKError 0x600002a5bb70: "Internal Error" (1/5000); "Failed to sync user keys"> share error Failed to sync user keys

when trying for example:

let shares = try await Self.container.privateCloudDatabase.recordZone(for: SharedZone.ID)

It only happens in a simulator. Does anyone have a similar issue?

Answered by newwbee in 723620022

Best to use a real device, it is fine if your device uses a different iCloud account (which is different from your Apple Dev account), you could login into CloudKit Console and use "Act as iCloud Account" to view your private database records

Accepted Answer

Best to use a real device, it is fine if your device uses a different iCloud account (which is different from your Apple Dev account), you could login into CloudKit Console and use "Act as iCloud Account" to view your private database records

Problem 1:

NSPersistentCloudKitContainer doesn't seem to work on simulator

Solution:

Use device, haven't found a way to make it work on the simulator.


Problem2

When using CloudKit APIs (not NSPersistentCloudKitContainer) on the simulator I was getting CKError.notAuthenticated even though I had signed into iCloud on the simulator

Root cause

This happens when 2FA was enabled on the iCloud account but the 2FA code was asked on the simulator

Solution

  1. Go to https://appleid.apple.com/, select devices on the sidebar
  2. Remove simulator (I found 2 simulators, removed both)
  3. Reset Xcode simulator
  4. Log into iCloud on the simulator
  5. Run the app

Hopefully that should work.

What worked for me is just:

  1. logging out of iCloud in Simulator
  2. selecting Device -> Restart in the menu
  3. logging back into iCloud

Little bit faster than the doing a full content reset.

Error: Failed to sync user keys in simulator
 
 
Q