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

How to handle Javascript callbacks in cordova iOS plugin

所以我有一个生成 uiView 的 cordova iOS 插件

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

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

如何以正确的方式执行此操作?

在事件中可能是这样的:

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]; 是关键,如果你不添加它,回调已完成,将不再接受进一步的事件。