So in IOS 9 it was possible to do this:
let subscription = CKQuerySubscription(recordType: "SomeType", predicate: somePredicate, subscriptionID: someSubscriptionID, options: [.firesOnRecordCreation, .firesOnRecordDeletion])
subscription.notificationInfo = ...
publicDatabase.save(subscription) { (savedSubscription, error) in }
However, now with Swift 3, CKQuerySubscription has been deprecated and CKDatabaseSubscription is recommended for a shared database. I have the following code:
let subscription = CKDatabaseSubscription(subscriptionID: someSubscriptionID)
subscription.recordType = "SomeType"
publicDatabase.save(subscription) { (savedSubscription, error) in }
The problem is that I don't see how one can specify the predicate and the subscription options using this method. Somebody please help.
CKQuerySubscription is not deprecated 100%. But its scope is changed
For Public Database default zone & Private Database Default zone use CKQuerySubscription for getting notification.
There is 2 Step process for Shared Database & Private Database Custom Zone.
Step 1: CKDatabaseSubscription to Private & Shared Database.
first step will get you zone add, zone update or zone delete notifications to private & shared database.
Step 2: Fetch all the custom zones from shared database & Private database. And create CKRecordZoneSubscription for every zone.
Note: CKQuerySubscription does not work for Shared Database but it will work for Private database custom zone where you can add predicate & notification options.
Because we created CKDatabaseSubscription in step 1. If there are any addition or changes or deletion of zone while we are fetching custom zones from Private & Shared database. You will get notification.
If notification type is .database then based on subscription ID fetch all zones from shared or private database.
If notification type is .recordZone then get zone ID and fetch record changes using previously saved server change token.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With