I'm developing a Cordova plugin for iOS. There's a method in my 'plugin.js' I call only once from my app (javascript) to start listening for callbacks from the native part. When calling this method, I'm storing the callbackId in the Objective-C class, and want to send the callback later on (multiple callbacks possible), so I use the stored callbackId to send the CDVPluginResult, and set 'keepCallback' to true. But callback never arrives in the 'plugin.js', therefor not in the app.
Objective-C Method 1 (that's the listener part):
- (void)listenForNews:(CDVInvokedUrlCommand *)command
{
self.storedCallbackId = command.callbackId;
...
Objective-C Method 2 (that's the method which is being called multiple times asynchronously)
- (void)onNewsReceived
{
CDVPluginResult* pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK];
[pluginResult setKeepCallbackAsBool:YES];
[self.commandDelegate sendPluginResult:pluginResult callbackId:self.storedCallbackId];
I've already verified that the 'storedCallbackId' is properly stored and read.
Any ideas?
I do something like the following in my plugin and it works, so give this a try:
- (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];
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.