Panel |
---|
|
Panel |
---|
|
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 |
---|
| 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 |
---|
|
Note |
---|
| 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.
NOTE: For older Pulsar versions, the 'syncData' API request will register and de-register for sync notifications automatically, restricting sync notification responses to PulsarAPI-initiated syncs. With the release of versions 2.1.6 (Android and UWP) and 3.1.0 (iOS) , this behavior can 'syncData' will maintain its current behavior, but now sync notification handlers can also be managed separately, using the 'registerSync' API method (see below).
|
Code Block |
---|
| 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 |
---|
title | Handling Sync Notifications |
---|
|
Info |
---|
| The Pulsar sync process provides a feedback mechanism for monitoring the overall progress of the sync.
WARNING: Once you have requested a sync, you should not perform any create/update/delete calls until sync has finished.
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 |
---|
| ......
// 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 |
---|
|
Info |
---|
title | syncDataUpdate 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: - "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
- "syncpercent" - This value will be delivered as a string containing a floating point value between 0 and 100.00. This value is relative to the current sync pass, so may reach 100.00 more than once.
|
Code Block |
---|
| // 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 |
---|
|
Info |
---|
title | syncDataFinished 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 |
---|
| // 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 |
---|
title | Register for Notifications |
---|
|
Info |
---|
| Once either or both of the sync progress and completion handlers have been registered with the Pulsar bridge, the 'registerSync' request can be used to enable these handlers to respond to any sync events that occur, not just JSAPI API initiated ones. This request takes a single boolean parameter to determine whether we are registering ("true") or de-registering ("false") for sync notifications.
NOTE: this is new functionality for Pulsar versions 2.1.6 (Android and UWP) and 3.1.0 (iOS) – in older releases the 'syncData' API request will register and de-register for sync notifications automatically, restricting this behavior to JSAPIAPI-initiated syncs. |
Code Block |
---|
| var request = {
"type" : "registerSync",
"data" : "TRUE" // required- this is the value to set "FALSE" for de-registering, "TRUE" for registering
};
bridge.sendRequest(request, function (results) {
if (results.type === "registersyncResponse") {
var registeredForSync = results.data.registered; //string value "TRUE" or "FALSE"
// do something with the information
} else if (results.type == 'error') {
errStr = results.data;
alert('A problem occurred:\n' + errStr);
}
});
|
|
|
Panel |
---|
|
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));
var syncSuccess = responseData.data.success;
} else if (responseData.type == 'error') {
var errStr = str(responseData.data);
console.log('A problem occurred:\n' + errStr);
}
}); |
|
|
Panel |
---|
|
Panel |
---|
|
Info |
---|
The getAutosyncStatus operation will return Pulsar's current auto-sync status. This is the functionality that controls whether a sync starts automatically on login and when you return to the app. This will return the string "FALSE" if this functionality is off, and "TRUE" if this functionality is turned on. |
Code Block |
---|
var request = {
"type" : "getAutosyncStatus",
"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 === "getAutosyncStatusResponse") {
var isAutoSyncOn = results.data; //string value "TRUE" or "FALSE"
// do something with the information
} else if (results.type == 'error') {
errStr = results.data;
alert('A problem occurred:\n' + errStr);
}
}); |
|
Panel |
---|
|
Info |
---|
The setAutosyncStatus operation will attempt to set Pulsar's current auto-sync status. Similar to getAutosyncStatus, this will return the string "FALSE" if this functionality is off after attempting to set it, and "TRUE" if this functionality is turned on after the attempt. |
Code Block |
---|
var request = {
"type" : "setAutosyncStatus",
"data" : "TRUE" // required- this is the value to set "FALSE" for off, "TRUE" for on
};
bridge.sendRequest(request, function (results) {
console.log('Javascript got its response: ' + str(results));
if (results.type === "setAutosyncStatusResponse") {
var isAutoSyncOn = results.data; //string value "TRUE" or "FALSE"
// do something with the information
} else if (results.type == 'error') {
errStr = results.data;
alert('A problem occurred:\n' + errStr);
}
}); |
|
|
|