简体   繁体   English

没有调用Cordova / phonegap JS回调

[英]Cordova/phonegap JS callbacks not invoked

I have made a cordova project via the create script and have created a plugin. 我通过创建脚本创建了一个cordova项目并创建了一个插件。 However, for some reason, the JS-callbacks are not invoked whenever i send an pluginresult. 但是,由于某种原因,每当我发送pluginresult时都不会调用JS回调。

I have checked the callbackID. 我检查了callbackID。 Its filled with a (seemingly) valid callback. 它充满了(看似)有效的回调。 My plugin mapping is ok, the native code gets executed and there are no errors. 我的插件映射没问题,本机代码被执行并且没有错误。

I have no clue as to why callbacks arent fired.. 我不知道为什么回调没有被解雇..

My javascript : 我的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 我的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];
}

i'm not a expert in phonegap but this works for me you can try (iOS Code) 我不是手机专家,但这对我有用,你可以尝试(iOS代码)

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

instead 代替

[self writeJavascript:javascript];

i hope this help 我希望这有帮助

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM