Last active
December 13, 2015 19:28
-
-
Save jinqian/4962360 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* 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