Sync Progress Events

Sync API allows you to subscribe to the sync progress events by providing a callback method. The current sync status is conveyed to the application through the sync phase and state. The Sync Progress Events feature is supported at Object and Object-Service level sync operations. In addition to sync progress events, sync stats can be obtained through sync success callback by opting for it through SyncOptions. Use getSyncStats key to opt for sync status, which would give out details of current sync operation such as the number of records downloaded and the number of objects synchronized in response to successful sync.

For information about Sync API and its options for different platforms, refer to Offline Objects API Guide.

Sync Progress Phases and States

The following table contains currently supported sync phase, sync state, and additional information sent in the event notification.

Phases State Description
Sync Started

The following details are sent in this phase and state

  • Sync start time
  • Object/Object Service name
  • Number of objects to sync
Sync Ended

The following details are sent in this phase and state

  • Object/Object Service name
  • Sync elapsed time
  • No of records uploaded
  • No of records downloaded
Upload Started

The following details are sent in this phase and state

  • Object/Object Service name
Upload InProgress

The following details are sent in this phase and state

  • Object/Object Service name
  • Number of records to upload
Upload Ended

The following details are sent in this phase and state

  • Object/Object Service name
  • No of records uploaded
Download Started

The following details are sent in this phase and state

  • Object/Object Service name
  • Current download batch number
Download InProgress

The following details are sent in this phase and state

  • Object/Object Service name
  • Current download batch number
Download Ended

The following details are sent in this phase and state

  • Object/Object Service name
  • The number of records downloaded.
  • Current download batch number.

Object Level

The following examples demonstrate subscribing to the sync progress events and the sync stats.

JavaScript



function onSyncSuccess(successObject) { //Operation to be performed on successful sync. } function onSyncFailure(err) { //Operation to be performed on unsuccessful sync. } function onSyncProgress(progressObject) { //Update Progressbar. } try { //Create an offline object which needs to be synced. var syncObject = = new kony.sdk.KNYObj("Employee"); //Set GetSyncStats to receive sync stats on sync success. var syncOptions = {"GetSyncStats" : "true"}; //Supplying callback to receive sync progress event too. syncObject.startSync(syncOptions, onSyncSuccess, onSyncFailure, onSyncProgress); } catch (err) { alert("Object creation failed!); }

Android



try { //Create an offline object which needs to be synced. private KNYObj syncObject = new KNYObj("Employee"); //Set GetSyncStats to receive sync stats on sync success. HashMap<String, Object> syncOptions = new HashMap<String, Object>(); syncOptions.put("GetSyncStats", "true"); //Supplying callback to receive sync progress event too. syncObject.startSync(syncOptions, new KNYCallback() { @Override public void onSuccess(Object successObject) { //Operation to be performed on successful sync. } @Override public void onFailure(Object error) { //Operation to be performed on unsuccessful sync. } }, new KNYProgressCallback() { @Override public void onProgress(Object object) { //Update Progressbar. } }); } catch (Exception e) { // Log "Object creation failed!" error }

iOS



NSError *error; KNYObj *syncObject = [[KNYObj alloc] initWithName:@"Employee" error:&error]; if(error) { NSLog(@"Object creation failed!"); } else { KNYSuccessCompletionHandler onSuccessHandler = ^(id successObject) { //Operation to be performed on successful sync. } KNYFailureCompletionHandler onFailureHandler = ^(id error) { //Operation to be performed on unsuccessful sync. } KNYProgressCompletionHandler onProgressHandler = ^(id progressObject) { //Update Progressbar } //Set GetSyncStats to receive sync stats on sync success. NSDictionary *syncOptions = @{@"GetSyncStats" : @"true"}; //Supplying callback to receive sync progress event too. [syncObject startSync:syncOptions onSuccess:onSuccessHandler onFailure:onFailureHandler onProgress:onProgressHandler]; }

For more information about object-service level APIs, refer to Offline Objects API Reference Guide.