<object>.cancelSync
The <object>.cancelSync function attempts to cancel an in progress object sync operation. The operation fails if the task syncing is already finished, throws an error, or does not support the Cancel operation.
Quantum Visualizer (JavaScript)
NOTE:
- Not supported for Mobile Web and Desktop Web channels.
- Supported for Windows from V8 SP4 Fix Pack 12 onwards.
Signature
<KNYObj>.cancelSync(options, onSuccess, onFailure);
Parameters
Parameter | Type | Description | Required |
options |
JSON | Reserved for future use, so the parameter is insignificant. But, the developer must pass some value such as null or { }. | Yes |
onSuccess | Function | The function is invoked when the cancellation is successful. | Yes |
onFailure | Function | The function is invoked when the cancellation fails. | Yes |
Return Type
void
Example
var syncObject = new kony.sdk.KNYObj("Managers"); // Define Sync options var syncOptions = {}; syncOptions.downloadBatchSize = 100; syncOptions.uploadBatchSize = 200; syncOptions.getSyncStats = true; // Start Sync asynchronously syncObject.startSync(syncOptions, function(res) { alert("Object sync successful”); }, function(err) { alert(" Object sync failed with error: " + JSON.stringify(err)); }, function(progressCallback) { alert(" Object sync progress event received "); }); // Now attempt to Cancel Sync // passing an empty map for options parameter syncObject.cancelSync({}, function(res) { alert(" Object sync cancellation successful "); }, function(err) { alert(" Object sync failed with error: " + JSON.stringify(err)); });
Android (Java)
Signature
public void cancelSync(HashMap<String, Object> options, final KNYCallback syncCancellationCallback)
Parameters
Parameter | Type | Description | Required |
options | HashMap<String, Object> | Reserved for future use, so the parameter is insignificant. But, the developer must pass some value such as null or new HashMap<String, Object>(). | Yes |
syncCancellationCallback | KNYCallback | Application implements onSuccess and onFailure methods of KNYCallback interface. | Yes |
Return Type
void
Example
KNYObj syncObject = new KNYObj("Managers"); //Define Sync options HashMap < String, Object > syncOptions = new HashMap < String, Object > (); syncOptions.put("downloadBatchSize", "100"); syncOptions.put("uploadBatchSize", "200"); syncOptions.put("getSyncStats", "true"); // Start Sync asynchronously syncObject.startSync(syncOptions, new KNYCallback() { @Override public void onSuccess(Object object) { Log.d("ObjectSync", "Object sync successful"); } @Override public void onFailure(Object error) { Log.e("ObjectSync", "Object sync failed with error: " + error); } }, new KNYProgressCallback() { @Override public void onProgress(Object object) { Log.d("ObjectSync", "Object sync progress event received"); } }); // Now attempt to Cancel Sync syncObject.cancelSync(new HashMap < String, Object > (), new KNYCallback() { @Override public void onSuccess(Object object) { Log.d("ObjectSync Cancellation", "Object sync cancellation successful"); } @Override public void onFailure(Object error) { Log.e("ObjectSync Cancellation", "Object sync cancellation failed with error: " + error); } });
iOS (Objective C)
Signature
(void)cancelSync:(NSDictionary *)options onSuccess:(KNYSuccessCompletionHandler)onSuccess onFailure:(KNYFailureCompletionHandler)onFailure
Parameters
Parameter | Type | Description | Required |
onSuccess | KNYSuccessCompletionHandler | The method called after a successful cancellation. | Yes |
onFailure | KNYFailureCompletionHandler | The method called after the cancellation fails. | Yes |
Return Type
void
Example
NSError * error; KNYObj * syncObject = [ [KNYObj alloc] initWithName: @"Managers" error: & error ]; // Define Sync options NSMutableDictionary * syncOptions = [NSMutableDictionary new]; [syncOptions setObject: @"100" forKey: @"downloadBatchSize" ]; [syncOptions setObject: @"200" forKey: @"uploadBatchSize" ]; [syncOptions setObject: @"true" forKey: @"getSyncStats" ]; // Start Sync asynchronously [syncObject startSync: syncOptions onSuccess: ^ (id object) { NSLog(@"Object sync successful"); } onFailure: ^ (NSError * error) { NSLog(@"Object sync failed with error: %@", [error description]); } onProgress: ^ (id object) { NSLog(@"Object sync progress event received"); } ]; // Now attempt to Cancel Sync // passing an empty dictionary for options parameter NSMutableDictionary * cancelSyncOptions = [NSMutableDictionary new]; [syncObject cancelSync: cancelSyncOptions onSuccess: ^ (id object) { NSLog(@"Object sync cancellation successful"); } onFailure: ^ (NSError * error) { NSLog(@"Object sync cancellation failed with error: %@", [error description]); } ];