Skip to content

Instantly share code, notes, and snippets.

@jinqian
Last active December 13, 2015 19:28
Show Gist options
  • Save jinqian/4962360 to your computer and use it in GitHub Desktop.
Save jinqian/4962360 to your computer and use it in GitHub Desktop.
/* MSHandler.m */
// Dispatched as soon as the synchronization progresses
// In this method we set "shouldKeepCallback" as YES since the sync is still in progress
- (void)didSyncWithProgress:(NSNumber *)current total:(NSNumber *)total {
int percent = 100 * [current floatValue] / [total floatValue];
[self.plugin returnSyncStatus:@""
status:2
progress:percent
callback:self.callback
shouldKeepCallback:YES];
}
// Dispatched when a synchronization is completed
// In this method we set "shouldKeepCallback" as NO since the sync has already ended
- (void)scannerDidSync:(MSScanner *)scanner {
MSDLog(@" [MOODSTOCKS SDK] SYNC SUCCEEDED (%d IMAGE(S))", [scanner count:nil]);
[self.plugin returnSyncStatus:@""
status:3
progress:100
callback:self.callback
shouldKeepCallback:NO];
[self release];
}
//...
/* MoodstocksPlugin.m */
// Sync status callback
- (void)returnSyncStatus:(NSString *)message
status:(int)status
progress:(int)progress
callback:(NSString *)callback
shouldKeepCallback:(BOOL)shouldKeepCallback {
// Collect different sync indicators in a NSDictionary
// Including the boolean for "should keep callback"
NSDictionary *statusDict = [NSDictionary dictionaryWithObjectsAndKeys:message, @"message",
[NSNumber numberWithInt:status], @"status",
[NSNumber numberWithFloat:progress], @"progress",
nil];
CDVPluginResult *result = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK
messageAsDictionary:statusDict];
[result setKeepCallbackAsBool:shouldKeepCallback];
NSString *js = [result toSuccessCallbackString:callback];
[self writeJavascript:js];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment