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
nil
to 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
nil
to remove the listener.Declaration
Swift
var completedListener: SyncCompletedListener? { get set }
-
Sets a listener to observe sync changes. Replaces a previously set listener. Set to
nil
to 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
nil
to 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
nil
to 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()
-
Sets 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
-
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 -> SuccessTimeOut
Parameters
timeoutMilliseconds
Must 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) throws
Parameters
milliseconds
interval in milliseconds; the default is 25 minutes (1 500 000 milliseconds), which is also the allowed maximum.