Question about sharing data via Cloudkit and Core Data - Creating CKShare

I am trying to use the new API provided by WWDC21 to create Core Data databases that can be shared.

When I do the sharing for an NSManageObject, I tried to experiment with 2 methods.

1: Using UICloudSharingController's

UICloudSharingController(preparationHandler: (UICloudSharingController, @escaping (CKShare?, CKContainer?, Error?) -> Void) -> Void)

method. Currently this method works and the participants can get all the data after accepting the invitation.

2:Use NSPersistentContainer's share(_ managedObjects: [NSManagedObject], to share: CKShare?) async throws -> (Set<NSManagedObjectID>, CKShare, CKContainer) method. First get ckshare, then call UICloudSharingController(share:, container: )

With this approach, after accepting the invitation, the participant only gets the data generated after the creation of the ckshare, and the data before the ckshare is never fetched

I'm not sure if it's an error in the token generated by the share method of the NSPersistentContainer or something else. Has anyone encountered a similar situation?

Sorry, I made a mistake in my description in the previous feedback. After continuous testing, I found that the problem is not with how to create ckshare, but with the sharing permissions.

When the owner sets the share permissions for the data to a specific icloud user, the program works perfectly. The participant can show the share record in their app as soon as they accept the invitation.

When the owner sets the data sharing permission to anyone, the participant does not show the shared data after accepting the invitation. Only when the owner makes changes to the data can it be displayed, and only the modified data can be displayed.

For example, a demo is provided in my GitHub
Shared Data for Note , Note has a relationship to multiple Memo When the owner shares a Note (sharing permission is set to anyone), the participant does not show the Note in the first time, and only after the owner adds a new Memo to the Note, the participant's app will show it, and only show that after the sharing is added.

When sharing for a specific icloud user, the participant can show the Note at the first time, and if the Note already has Memo data at the time of sharing, the participant will also show all the Memo data added before sharing.

May I ask if this is the logical mechanism of sharing preset? Or is it a bug?

Question about sharing data via Cloudkit and Core Data - Creating CKShare
 
 
Q