如何在cordova iOS插件中处理Javascript回调

时间:2015-10-28 06:55:38

标签: ios cordova native cordova-plugins

所以我有一个生成uiView

的cordova iOS插件

[self.pluginviewContoller presentViewController:self.myView animated:YES completion:nil];

现在在视图控制器中我想对特定事件的javascript代码进行回调。我已经尝试实例化继承CDVPlugin的类,但它不起作用。

如何以正确的方式做到这一点?

1 个答案:

答案 0 :(得分:0)

在事件上可能是这样的事情:

NSDictionary *payload = [NSDictionary dictionaryWithObjectsAndKeys:
    messageParameter1, @"message1", 
    messageParameter2, @"message2", 
    nil];

CDVPluginResult* pluginResult = nil;
pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsDictionary:payload];
[pluginResult setKeepCallbackAsBool:YES];

[self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];

[pluginResult setKeepCallbackAsBool:YES];是关键,就好像你没有添加它一样,回调已经完成,并且不再接受任何事件。