Fetching a CKShare (URL)
Supplementing Incomplete Documentation
Unfortuantely, CloudKit sharing isn’t the most well documentated API. This is a bit strange to me, and I’m sure anyone else who uses it, considering its scale in Apple’s first party apps: Numerbs, Pages, Keynote, Notes, etc.
Not too long ago I wrote a series of articles on programmaticly creating a CKShare. It was a really great excerise to help me understand the underlying workflow and architecture of show sharing works…plus I need it for my app Significant Other.
Using the UICloudSharingController doesn’t allow for restricting the number of participants to only 1, thus my need to get closer to the metal.
With any multi-step process there are incidents which could cause the workflow to fail between User A and User B. With the most recent update to Significant Other that I’m currently working on I want to give the owner of the share, in this scenario User A, the ability to resend the share link to User B.
As I started to write the feature I find out pretty quickly that solutions weren’t as straight forward as I would have hoped. When the owner creates the share you need to persist the url, share or root record / shareID.
Neccessity Gives Birth to Solution
Since I wasn’t able to use a local copy of the share from methods listed above I had to find another path. Though I don’t persist the CKShare, url or root record locally for the owner, I do persist the CKRecordZoneID.
3 Step Process
Armed with the CKRecordZoneID you need to
- Instantiate the record with the appropriate predicate
- Fetch the record from CloudKit
- Fetch the share for that record
There might be a better way, but I like having to grab the latest / greatest version of the share to insure of the most up to date properties and meta-data.