Javascript 未调用Cordova插件回调(iOS)

Javascript 未调用Cordova插件回调(iOS),javascript,ios,objective-c,cordova,ionic-framework,Javascript,Ios,Objective C,Cordova,Ionic Framework,我正在为iOS开发Cordova插件。在我的“plugin.js”中有一个方法,我只从我的应用程序(javascript)调用一次,开始监听来自本机部分的回调。调用此方法时,我将callbackId存储在Objective-C类中,并希望稍后发送回调(可能有多个回调),因此我使用存储的callbackId发送CDVPluginResult,并将“keepCallback”设置为true。但是callback永远不会出现在“plugin.js”中,因此不会出现在应用程序中 目标C方法1(即听众部分

我正在为iOS开发Cordova插件。在我的“plugin.js”中有一个方法,我只从我的应用程序(javascript)调用一次,开始监听来自本机部分的回调。调用此方法时,我将callbackId存储在Objective-C类中,并希望稍后发送回调(可能有多个回调),因此我使用存储的callbackId发送CDVPluginResult,并将“keepCallback”设置为true。但是callback永远不会出现在“plugin.js”中,因此不会出现在应用程序中

目标C方法1(即听众部分):

Objective-C方法2(即异步多次调用的方法)

我已经验证了“storedCallbackId”是否正确存储和读取


有什么想法吗?

我做了以下类似的事情,效果很好,所以请尝试一下:

- (void)listenForNews:(CDVInvokedUrlCommand *)command
{
   self.storedCallbackId = command.callbackId;
   ...
   CDVPluginResult* pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_NO_RESULT];
   [pluginResult setKeepCallback:[NSNumber numberWithBool:YES]];
   [self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];


- (void)onNewsReceived
{
   CDVPluginResult* pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK];
   [pluginResult setKeepCallback:[NSNumber numberWithBool:YES]];
   [self.commandDelegate sendPluginResult:pluginResult callbackId:self.storedCallbackId];

我做了以下类似的事情,效果很好,所以请尝试一下:

- (void)listenForNews:(CDVInvokedUrlCommand *)command
{
   self.storedCallbackId = command.callbackId;
   ...
   CDVPluginResult* pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_NO_RESULT];
   [pluginResult setKeepCallback:[NSNumber numberWithBool:YES]];
   [self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];


- (void)onNewsReceived
{
   CDVPluginResult* pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK];
   [pluginResult setKeepCallback:[NSNumber numberWithBool:YES]];
   [self.commandDelegate sendPluginResult:pluginResult callbackId:self.storedCallbackId];

谢谢@DaveAlden。我们可以解决这个问题。最后是插件类的多个实例的问题,这导致Cordova失去了回调(当然)。谢谢!我能够在我一直在开发的Swift插件中实现这一点。这是我需要的最后一个小部件!非常感谢。我实现了相同的功能,但是回调仅第一次到达.js文件。对于下一次委托方法调用,它不再调用。请帮忙。谢谢@DaveAlden。我们可以解决这个问题。最后是插件类的多个实例的问题,这导致Cordova失去了回调(当然)。谢谢!我能够在我一直在开发的Swift插件中实现这一点。这是我需要的最后一个小部件!非常感谢。我实现了相同的功能,但是回调仅第一次到达.js文件。对于下一次委托方法调用,它不再调用。请帮忙。
- (void)listenForNews:(CDVInvokedUrlCommand *)command
{
   self.storedCallbackId = command.callbackId;
   ...
   CDVPluginResult* pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_NO_RESULT];
   [pluginResult setKeepCallback:[NSNumber numberWithBool:YES]];
   [self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];


- (void)onNewsReceived
{
   CDVPluginResult* pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK];
   [pluginResult setKeepCallback:[NSNumber numberWithBool:YES]];
   [self.commandDelegate sendPluginResult:pluginResult callbackId:self.storedCallbackId];