I have a Phonegap Cordova plugin. In this plugin I receive a click event from javascript.This click triggers a file download using my client library. This file download sends events and calls methods in my plugin, as I have set it to be delegate.
I can't manage to sends those events back to the javascript using 'stringByEvaluatingJavaScriptFromString' It seems like it doesn't triggers the call.
It's working when I try to call it after a javascript click to the echo Plugin method.
Here is the .m plugin class :
#import "CCDataBundlePlugin.h"
#import <Cordova/CDV.h>
@implementation CCDataBundlePlugin
-(id)init{
[MYCLIENTLIB sharedInstance].delegate = self;
self = [super init];
return self;
}
- (void)echo:(CDVInvokedUrlCommand*)command
{
NSLog(@"------ Received click");
CDVPluginResult* pluginResult = nil;
NSString* echo = [command.arguments objectAtIndex:0];
if (echo != nil && [echo length] > 0) {
pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsString:echo];
} else {
pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR];
}
// When latest extraction succeeded, call next download
[[MYCLIENTLIB sharedInstance] downloadBundlesForChannel:@"myChannel"];
// When latest download succeeded, call next extraction
[[MYCLIENTLIB sharedInstance] extractBundlesForChannel:@"myChannel"];
[self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
}
-(void)callJavascriptMethodWithString:(NSString*)stringParameter{
NSString* jsString = [NSString stringWithFormat:@"CN.Interface.Recepter.receiveWithString(\"%@\");", stringParameter];
//The line under is not working, I don't get the function call in JS
[self.webView stringByEvaluatingJavaScriptFromString:jsString];
}
// DOWNLOAD EVENTS Called from the Library
- (void)dataBundle:(MYCLIENTLIB *)dataBundle downloadDidStartForChannelIdentifier:(NSString *)channelIdentifier {
NSLog(@"download in progress..."); // this is logged
[self callJavascriptMethodWithString:@"download in progress..."];
// The line above do calls the method
}