Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Section


Panel
titleData Sync


Panel
titlesyncinfo


Info

The syncinfo query returns the following information about the last Pulsar sync:

  • Last Sync Attempt Date/Time
  • Last Successful Sync Date/Time


Code Block
languagejs
var request = { 
	"type" : "syncinfo",
	"data" : { } // empty object- this is required in the current API
};

bridge.sendRequest(request, function (results) {
	console.log('Javascript got its response: ' + str(results));
    if (results.type === "syncinfoResponse")	{
		var lastsyncattempt = results.data.lastsyncattempt;
        var lastsuccessfulsync = results.data.lastsuccessfulsync;
    } else if (results.type == 'error') {
	    errStr = results.data;
	    alert('A problem occurred:\n' + errStr);
    }
});    



Panel
titlesyncdata


Note
iconfalse

The syncdata request will attempt to initiate a Pulsar sync action. This method is equivalent to pressing the "Sync now" button from the native Pulsar home screen. 


Code Block
languagejs
var request = { 
	"type" : "syncdata",
	"data" : { } // empty object- this is required in the current API
};

bridge.sendRequest(request, function (results) {
	console.log('Javascript got its response: ' + str(results));
	if (results.type === "syncDataResponse")	{
		// successfully requested sync
	} else if (results.type == 'error') {
		 errStr = results.data;
		 alert('A problem occurred:\n' + errStr);
	}
});



Panel
titleHandling Sync Notifications


Info
titleOverview

The Pulsar sync process provides a feedback mechanism for monitoring the overall progress of the sync. You can hook into progress and completion notifications from javascript by registering handler functions with the Pulsar bridge. There can only be one handler assigned to a given handler name. See the examples of handler setup below:


Code Block
languagejs
......
// during bridge initialization
bridge.addHandler = function(handlerName, handler) {
	window.WebViewJavascriptBridge.registerHandler(handlerName, handler);
};
bridge.removeHandler = function(handlerName) {
    window.WebViewJavascriptBridge.deregisterHandler(handlerName);
};
......

// Add a handler
bridge.addHandler("handlerA", function(data) { console.log("handlerA called from Pulsar"); });

doSomethingThatMakesPulsarCallHandlerA();

// Remove a handler
bridge.removeHandler("handlerA");


Panel
titleSync Progress


Info
titlesyncDataUpdate handler

To receive progress updates during a sync initiated with the syncData request, register a handler with the name "syncDataUpdate". This function will receive an object with the progress information:

  1. "syncpass" - The Pulsar sync may take one or more passes to fully complete. This will be delivered as a string containing the pass number, an integer value
  2. "syncpercent" - This value will be delivered as a string containing a floating point value between 0 and 100.00


Code Block
languagejs
// Add a handler to respond to sync progress updates
bridge.addHandler("syncDataUpdate", function(dataObj) {
    if (dataObj.hasOwnProperty("syncpercent") && dataObj.hasOwnProperty("syncpass")) {
        var syncPass = dataObj.syncpass;
		var syncPercent = dataObj.syncpercent;
		someScreenUpdate(syncPass, syncPercent);
		....
    }
});



Panel
titleSync Completion


Info
titlesyncDataFinished handler

To receive completion notifications for a sync initiated with the syncData request, register a handler with the name  "syncDataFinished". This function will receive an object with the completion success status.


Code Block
languagejs
// Add a handler to respond to sync finished event
bridge.addHandler("syncDataFinished", function(dataObj) {
    console.log("sync data finished");
    if (dataObj.hasOwnProperty("success")) {
        if (dataObj.success) {
            doSyncSuccess();
        } else {
            doSyncFailure();
        }
    }
});




Panel
titleinterruptsync


Info

The interruptsync request will attempt to stop the currently running sync, if any.


Code Block
var request = { 
	"type" : "interruptsync",
	"data" : { } // empty object- this is required in the current API
};
bridge.sendRequest(request, function(responseData) {
    if (responseData.type === "interruptSyncResponse") {
        console.log('interruptSync: ' + str(responseData.data));
        success(var syncSuccess = responseData.data).success;
    } else if (responseData.type == 'error') {
        var errStr = str(responseData.data);
        console.log('A problem occurred:\n' + errStr);
    }
});




...