【发布时间】:2013-07-25 19:53:12
【问题描述】:
我有一个 Phonegap Cordova 插件。在这个插件中,我收到了来自 javascript 的点击事件。这个点击触发了使用我的客户端库的文件下载。 此文件下载在我的插件中发送事件并调用方法,因为我已将其设置为委托。
我无法使用 'stringByEvaluatingJavaScriptFromString' 将这些事件发送回 javascript 似乎它不会触发调用。
当我在 javascript 单击 echo Plugin 方法后尝试调用它时,它正在工作。
这是 .m 插件类:
#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
}
【问题讨论】:
标签: javascript objective-c cordova