SyncClient
public protocol SyncClient : AnyObject
Main API for client sync; create an instance via Sync.makeClient(). The sync client will start trying to connect after start() is called.
-
Undocumented
Declaration
Swift
var callListenersInMainThread: Bool { get set } -
Sets a listener to observe login events. Replaces a previously set listener. Set to
nilto remove the listener.Declaration
Swift
var loginListener: SyncLoginListener? { get set } -
Sets a listener to observe sync completed events. Replaces a previously set listener. Set to
nilto remove the listener.Declaration
Swift
var completedListener: SyncCompletedListener? { get set } -
Sets a listener to observe sync changes. Replaces a previously set listener. Set to
nilto remove the listener.Declaration
Swift
var changeListener: SyncChangeListener? { get set } -
Sets a listener to observe sync connection events. Replaces a previously set listener. Set to
nilto remove the listener.Declaration
Swift
var connectionListener: SyncConnectionListener? { get set } -
Sets a listener to observe all sync events. Replaces a previously set listener. Set to
nilto remove the listener.Note
This replaces any specific listeners, e.g. a login listener.Declaration
Swift
var listener: SyncListener? { get set } -
Configures how sync updates are received from the server. If automatic sync updates are turned off, they will need to be requested manually.
Declaration
Swift
var updateRequestMode: RequestUpdatesMode { get set } -
Gets the current sync client state.
Declaration
Swift
func getState() -> SyncState -
Gets the current sync client state as a String.
Declaration
Swift
func getStateString() -> String -
Returns if this sync client is closed and can no longer be used.
Declaration
Swift
func isClosed() -> Bool -
Closes and cleans up all resources used by this sync client. It can no longer be used afterwards, make a new sync client instead. Does nothing if this sync client has already been closed.
Declaration
Swift
func close() -
Adds or replaces a Sync filter variable value for the given name.
Eventually, existing values for the same name are replaced.
Sync client filter variables can be used in server-side Sync filters to filter out objects that do not match the filters. Filter variables must be added before login, so before calling
start().See also
removeFilterVariable(_:)See also
removeAllFilterVariables()Declaration
Swift
func putFilterVariable(name: String, value: String) throws -
Removes a previously added Sync filter variable value.
See also
putFilterVariable(name:value:)See also
removeAllFilterVariables()Declaration
Swift
func removeFilterVariable(_ name: String) throws -
Removes all previously added Sync filter variable values.
See also
putFilterVariable(name:value:)See also
removeFilterVariable(_:)Declaration
Swift
func removeAllFilterVariables() throws -
Sets credentials to authenticate the client with the server. Build credentials using e.g.
SyncCredentials.makeSharedSecret(secret).Declaration
Swift
func setCredentials(_ credentials: SyncCredentials) throws -
Sets multiple credentials to authenticate the client with the server. Build credentials using e.g.
SyncCredentials.makeSharedSecret(secret).Declaration
Swift
func setCredentials(_ credentials: [SyncCredentials]) throws -
Once the sync client is configured, you can “start” it to initiate synchronization. This method triggers communication in the background and will return immediately. If the synchronization destination is reachable, this background thread will connect to the server, log in (authenticate) and, depending on “update request mode”, start syncing data. If the device, network or server is currently offline, connection attempts will be retried later using increasing backoff intervals.
Declaration
Swift
func start() throws -
Stops this sync client. Does nothing if it is already stopped or closed.
Declaration
Swift
func stop() throws -
If automatic updates have been turned off via
updateRequestMode, this allows manual interaction: requests the latest updates from the server once (without subscribing for future updates).Declaration
Swift
@discardableResult func requestUpdates() throws -> Bool -
If automatic updates have been turned off via
updateRequestMode, this allows manual interaction: requests the latest updates from the server and subscribes for future updates, which the server will “push”. Note: usecancelUpdates()to stop receiving further updates (pushes).Declaration
Swift
@discardableResult func requestUpdatesAndSubscribe() throws -> Bool -
Requests the server to stop sending updates. Use
requestUpdates()orrequestUpdatesAndSubscribe()to request updates again.Declaration
Swift
@discardableResult func cancelUpdates() throws -> Bool -
Count the number of messages in the outgoing queue, i.e. those waiting to be sent to the server.
Counts all messages without any limitation. To apply a limit, use
outgoingMessagesCount(limit:).Note: This call uses a (read) transaction internally: 1) It’s not just a “cheap” return of a single number. While this will still be fast, avoid calling this function excessively. 2) The result follows transaction view semantics, thus it may not always match the actual value.
Declaration
Swift
func outgoingMessagesCount() throws -> UInt -
Like
outgoingMessagesCount(), but counts messages up to a limit that’s enough for your app logic.Declaration
Swift
func outgoingMessagesCount(limit: UInt) throws -> UIntParameters
limitpass 0 to count all messages without any limitation or a number that’s low enough for your app logic.
-
Experimental/Advanced API: requests a sync of all previous changes from the server.
Declaration
Swift
@discardableResult func fullSync() throws -> Bool -
Waits for the sync client to get into SyncState.loggedIn or until the given timeout is reached. For an asynchronous alternative, please check the listeners.
Declaration
Swift
func waitForLoggedInState(timeoutMilliseconds: UInt) throws -> SuccessTimeOutParameters
timeoutMillisecondsMust be greater than 0
-
Sends a heartbeat immediately, e.g. to detect that the network connection is still operational.
Declaration
Swift
@discardableResult func sendHeartbeat() throws -> Bool -
Sets the interval in which the client sends “heartbeat” messages to the server, keeping the connection alive. To detect disconnects early on the client side, you can also use heartbeats with a smaller interval. Use with caution, setting a low value (i.e. sending heartbeat very often) may cause an excessive network usage as well as high server load (with many clients).
Throws
if value is not in the allowed range, e.g. larger than the maximum (1 500 000).Declaration
Swift
func setHeartbeatInterval(milliseconds: UInt) throwsParameters
millisecondsinterval in milliseconds; the default is 25 minutes (1 500 000 milliseconds), which is also the allowed maximum.
View on GitHub
Install in Dash
SyncClient Protocol Reference