Subsequent callbacks from a Cordova iOS plugin don't fire

后端 未结 1 1254
梦毁少年i
梦毁少年i 2020-12-31 18:31

I have troubles with firing immediately subsequent callbacks from a cordova plugin (an iOS one). In XCode debugger I clearly see it steps over

[self.commandD         


        
相关标签:
1条回答
  • 2020-12-31 19:17

    So, the issue wasn't in threading/queueing.

    It turned out that you are allowed to use a callbackId only once unless you tell Cordova not to cleanup that callbackId by setting CDVPluginResult.keepCallback to true. Pay attention that keepCallback isn't a BOOL property, so you may need to call [pluginResult setKeepCallbackAsBool:YES];

    CDVPluginResult* pluginResult = [sendPluginResult resultWithStatus:CDVCommandStatus_OK messageAsString:key];
    [pluginResult setKeepCallbackAsBool:YES]; // here we tell Cordova not to cleanup the callback id after sendPluginResult()
    [self.commandDelegate sendPluginResult:pluginResult callbackId:monitoredRegions.callbackId];
    

    What messes things up is that if you introduce a blocking call like alert() in that callback, Cordova will let you make multiple successive sendPluginResult with the same callbackId.

    Keep in mind that you may need to sendPluginResult with a CDVPluginResult which keepCallback is false to release the callbackId that you don't need anymore.

    0 讨论(0)
提交回复
热议问题