Cordova / JS callbacks not called

I created a cordova project through script creation and created a plugin. However, for some reason, JS callbacks are not called whenever I send pluginresult.

I checked the callbackID. It fills (apparently) with a valid callback. My display of plugins is fine, my own code starts and there are no errors.

I don't know why callbacks arent fired.

My javascript:

(function(cordova) { function Plugin() {} Plugin.prototype.FBAuthorize = function(config) { cordova.exec(null, null, "Plugin", "FBAuthorize", []); }; Plugin.prototype.FBGetLoginStatus = function(cb, fail) { cordova.exec(function(){alert('test')}, function(){alert('test')}, "Plugin", "FBGetLoginStatus", []); } Plugin.prototype.FBPostToUserTimeline = function(textToShare, imageUrl, linkUrl) { cordova.exec(null, null, "Plugin", "FBPostToUserTimeline", [textToShare, imageUrl, linkUrl]); } if(!window.plugins) window.plugins = {}; window.plugins.Plugin = new Plugin(); })(window.cordova || window.Cordova || window.PhoneGap); 

my ios

 (void) FBGetLoginStatus:(CDVInvokedUrlCommand*)command { CDVPluginResult* result = nil; NSString* javascript = nil; if([[FBSession activeSession] isOpen]) { result = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsString:@"Logged in"]; javascript = [result toSuccessCallbackString:command.callbackId]; } else { result = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsString:@"Not logged in"]; javascript = [result toErrorCallbackString:command.callbackId]; } [self writeJavascript:javascript]; } 
+4
source share
1 answer

I am not an expert on the phone, but it works for me, you can try (iOS code)

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

instead

 [self writeJavascript:javascript]; 

I hope this help

0
source

Source: https://habr.com/ru/post/1444061/


All Articles