0
votes

I am new to subscriptions and Cloudkit and I am trying to setup subscriptions to send a push notification whenever CKShare records are created, edited, deleted, as well as when a participant leaves the share for both the private and shared database.

In my application I have two record types in Cloudkit. The first is Deck and second is Card. Deck has a one-to-manyrelationship with Card. Each Card holds a CKReference to its Deck. I have noticed in the Cloudkit dashboard there is a third record type named cloudkit.share. From my research I believe I will need four subscriptions here. One each for Deck and Card on the private database using a CKQuerySubscription and one each for Deck and Card on the shared database when the user accepts a share using a CKDatabaseSubscription. Will I also need to create another subscription on each database for the record type cloudkit.share as well, totaling six subscriptions?

Thank you

1
Create CKDatabaseSubscription for private and shared database. That way any changes made to your private or shared database would be sent as notifications. This include adding / removing / updating of records / shares. There are some WWDC videos on this, watch them.user1046037
Your comment does help with what to do with the cloudkit.share records that is returned from fetching the changed records. Wy do I get one back when I fetch changed records.Patrick Miron

1 Answers

1
votes

After setting up a single CKDatabaseSubscription on the both the shared and private databases, any changes will trigger the AppDelegate method:

-(void)application:(NSApplication *)application didReceiveRemoteNotification:(nonnull NSDictionary<NSString *,id> *)userInfo

The shared database is a little more complicated as you can’t query the default zone. You’ll need to set up an initial CKFetchDatabaseChangesOperation using setRecordZoneWithIDChangedBlock:^(CKRecordZoneID * _Nonnull zoneID) to get the shared record zoneID. With this you can query all shared records in the same way as the private database.

Don’t forget to delete Subscriptions from CloudKitDashboard when testing as subscriptions will remain and fire, even if removed from your code.