UICloudSharingController sharing via Messages broken in iOS16

In the summer, Apple published an informative sample app on sharing objects between iCloud users using Core Data, CloudKit and UICloudSharingController in SwiftUI: https://developer.apple.com/documentation/coredata/sharing_core_data_objects_between_icloud_users

However, Apple also announced the new Collaboration features for Messages in iOS16.

Now, it seems Collaboration is incompatible with UICloudSharingController and the sharing sheet it invokes, on iOS16.

MRE: See the Apple sample app linked above.

Reproduction:

  1. Create new share,
  2. Manage share with UICloudSharingController,
  3. Share With More People,
  4. Share using Messages (may succeed first time but fails on subsequent attempts on iOS16. Works great on iOS15).

Expectation: We can use UICloudSharingController to add new participants, using Messages, Mail or other platforms. The link will display correctly on all devices.

Reality: On iOS16+, attempting to share via Messages engages the "Collaboration" framework and leads to an alert: "An Error Occurred. Unable to start collaboration" (see Image 1). Triggering this error breaks ANY further shares - the link now cannot be created for Mail and other platforms either (see Image 2). Furthermore, if the first attempt succeeds, the link does not appear correctly on the receiving device (see Image 3). The link appears correctly when sent from a device running iOS15.

Question: How can this be resolved, so that we can share CloudKit records between users using Messages in iOS16+?

Images: https://imgur.com/a/o1fdABT

Answered by Cardu6lis in 733595022

As of iOS 16.0.3, this issue appears to have gone away when using the Apple sample app. I am still using the same downloaded code, so a fix was possibly made by Apple on CloudKit side of things.

After investigating, I still encountered the issue when invoking UICloudSharingController using UIViewControllerRepresentable (like in the RayW sample code).

The issue does not appear (anymore) when invoking UICloudSharingController using UIViewController (like in the Apple sample code).

On further inspection, the following console message appears when this issue happens for the first time:

CoreDataCloudKitShare[3672:1242159] systemSharingUIDidSaveShareBlock received error: <CKError 0x28314d8c0: "Server Record Changed" (14/2004); server message = "client oplock error updating record"; op = 134D57570A63DF3A; uuid = 8F070F8B-0AC0-4FFE-A52D-154BCBF3196C; container ID = “containerID>

Where containerID is the CKContainer ID, like “iCloud.com.company.samples.CoreDataCloudKitShare”. The message does not appear on subsequent attempts to add more people.

please file a bug report in the Feedback Assistant app.

On further inspection, the same problem also manifests in other samples which use CoreData+CloudKit sharing, for example: https://www.raywenderlich.com/29934862-sharing-core-data-with-cloudkit-in-swiftui

The problem does NOT appear in samples that use pure CloudKit, such as: https://github.com/apple/sample-cloudkit-sharing

This leads me to suppose there is something weird going on between Core Data and UICloudSharingController.

Submitted as FB11623246

A bug report was submitted as FB11623246

I am also experiencing the exact same problem

Accepted Answer

As of iOS 16.0.3, this issue appears to have gone away when using the Apple sample app. I am still using the same downloaded code, so a fix was possibly made by Apple on CloudKit side of things.

After investigating, I still encountered the issue when invoking UICloudSharingController using UIViewControllerRepresentable (like in the RayW sample code).

The issue does not appear (anymore) when invoking UICloudSharingController using UIViewController (like in the Apple sample code).

Were you able to make it work? I'm facing similar issue with Apple Mail app. I'm getting the prompt that I've attached and the log says "systemSharingUIDidSaveShareBlock received error: <CKError 0x2801d9500: "Permission Failure" (10/2007); server message = "Invalid bundle ID for container"; op = 33F7539C6A16E928; uuid = DF53ACF4-73AE-4763-947E-2A3FA7E4F241; container ID = "iCloud.my.container.id">". This only happens with Apple mail. other options like Messages, Gmail and Link sharing "Invite with link" work. Sharing with Apple mail stopped working after upgrading to iOS 16.

This is now confirmed by Apple as a known bug with high priority. A detailed, up-to-date post is kept at SO: https://stackoverflow.com/questions/73888519/uicloudsharingcontroller-does-not-work-for-core-data-with-cloudkit

UICloudSharingController sharing via Messages broken in iOS16
 
 
Q