I have an app that already uses CloudKit to pass information between the iPhone and Apple Watch App. I'd like to add the ability to let users share their data saved in iCloud with other users. I haven't found any great resources so far. My understanding is that Apple recommends setting up the share logic using UICloudSharingController
, but this would need to be wrapped in a UIHostingController
for SwiftUI. I found this answer but the code posted uses a few custom properties such as ObjectToShare
that I can't follow how were set up. Do I have to use UICloudSharingController
? Can I just have one user get their own shareURL and text it to another user? If so, how would user 1 get their own shareURL?
You don't have to use UICloudSharingController
, no. You can set up your own CKShare
object manually. It has a url
property that is what a user needs to click on in order to gain access to the CKRecord
you are sharing. So you can display the url
in a custom way or pass it around however you like.
The CKShare docs show all the available properties: https://developer.apple.com/documentation/cloudkit/ckshare
This article is a little old, but it helped me see the overall process of setting up a CKShare
: https://kwylez.medium.com/cloudkit-sharing-series-creating-the-ckshare-40e420b94ee8