Data Sync (Legacy)
This article provides step-by-step instructions for setting up, maintaining, and ending data subscriptions for peer-to-peer asynchronous replication:
To set up a replication subscription in your app:
Syncing large documents can significantly impact sync performance:
To initiate replication, early in your app lifecycle, such as within AppDelegate.application(_:didFinishLaunchingWithOptions:) or Application.onCreate methods, call the startSync method.
You only need to call the following function once.
You must start replication (startSync) in the top-most scope to ensure that as soon as your app starts, it automatically connects with the mesh network and remains active throughout your app's lifecycle.
Otherwise, the peer-to-peer connection may fail, resulting in remote peers becoming unable to send you updates in realtime.
For example, the following snippet demonstrates how to establish a carsSubscription to listen for all updates to documents in the "cars" collection with a field of color set to the value "blue":
For example, continuing with the previous example, the following snippet illustrates canceling the carsSubscription: