4

Say I am making Root <-> Child application (i.e. Manager <-> Employee).

Say Manager has predefined email and already granted userDiscoverability application permission (via CKContainer.requestApplicationPermission).

When Employee starts application, initialisation sequence automatically creates CKRecord (i.e. Employee record for time tracking), CKShare and silently invites Manager to CKShare.

For achieving this I am using CKContainer.discoverUserIdentity, then CKContainer.fetchShareParticipant, then CKModifyRecordsOperation which saves both CKRecord and CKShare.

After initialisation flow in private database of Employee I have record type of cloudkit.share which has 2 participants, Employee itself and Manager. Acceptance status of Manager is INVITED. Also I have URL link which I got after saving CKShare.

Now on Manager side I want silently accept CKShare invitation in order to access Employee record (i.e. for time tracking).


How to silently accept CKShare invitation without need of sending URL link via email, Messages.app, without using UICloudSharingController, etc.?

Is it possible to purely programmatically, silently, using CloudKit only share CKShare from one side and accept it on other side?

Thank you!

Vlad
  • 6,402
  • 1
  • 60
  • 74
  • 1
    Vlad, I too would like to do this, got a little further by opening the URL with code, but ran out of time to get anywhere with this. Did you hear any more? If I could I would pitch in on a reward to get an answer? – user3069232 Jul 03 '18 at 05:52
  • 1
    The key to the puzzle is that the other party needs to do the accepting, you can not do it for them, so you need to transmit the link come what may. – user3069232 Jul 03 '18 at 06:37
  • 1
    I created another `CKRecord` to keep `CKShare` URL. After creating share on `Employee` side the result URL saved into Public Database. `Manager` gets subscription notification that Public Database was changed. After fetching changes it opens URL programmatically. As result `CKShare` is accepted. It still prototype but seems working.) – Vlad Jul 15 '18 at 14:24
  • 1
    Vlad, I have noticed you need to be really careful with the parent share on this in terms of timing. I too create a parent share and then assign it to the records I want share. But it seems to fail even after I have confirmed the parent share is readable if I don't give it a few seconds or so to complete. – user3069232 Jul 17 '18 at 19:32
  • Thanks for the info. It's defenetely help me out... But quick question, what do you do with the cloudkit.share record we get from fetchChangeZone? Is it just for notifying us of the "acceptance" status. Do we have the save it's token in the local database. I'm a bit confused on that... I would appreciate someone pointing me in the right direction. I can't find anyone mentioning that cloudkit.share record we get back and it breaks my current saving to my local database routine... – Patrick Miron Aug 31 '18 at 14:39
  • On receiving `CKDatabaseNotification` about changes in shared DB I am fetching all record zones in shared DB (aka `foreign user records`) and then fetching changes from all zones in shared DB using previously saved cursor (if any). Then updating local cache (CoreData DB) using custom merge logic. – Vlad Aug 31 '18 at 14:52
  • Did you find a solution? – erotsppa Feb 08 '20 at 06:26

0 Answers0