Saves one or more subscriptions to record changes.
- CloudKit JS 1.1+
Possible values are:
Instead of fetching records, you can subscribe to changes, and let the server run the query in the background. You subscribe to changes by creating a subscription, represented by a
Cloud dictionary, and saving it to a database. Then you register for push notifications and handle them when they arrive.
Subscribing to Zone Changes
To subscribe to all changes in a zone, set the
subscription key to
zone and set the
zone key to the name of the zone you want to observe.
Save the subscription using the
Subscribing to Record Changes Using a Query
Create a query subscription object (a
Cloud dictionary with the
subscription key set to
query) specifying the record type, matching criteria, and types of changes you want to be notified about. Then save the query subscription object to the database.
For example, subscribe to receive new artwork from an artist where the
artist field in the
Artwork record type is a
Reference type. First create a reference to the
Artist record to use in the query.
Create a query subscription object specifying
Artwork records whose
artist field matches the
Reference object. Use the
fires key to specify the types of operations that fire this subscription.
Handling Subscription Push Notifications
Registering for Subscription Push Notifications
Saving subscriptions to the database doesn’t automatically configure your web app to receive notifications when a subscription fires. CloudKit uses the Apple Push Notification service (APNs) to send notifications, so your web app needs to register for push notifications to receive them.