4
我通過創建腳本創建了一個cordova項目並創建了一個插件。 但是,由於某種原因,只要我發送pluginresult,JS回調就不會被調用。Cordova/phonegap未被調用的JS回調
我檢查了callbackID。它充滿了(看似)有效的回調。 我的插件映射沒問題,本機代碼得到執行並且沒有錯誤。
我不知道,爲什麼回調的arent解僱..
我的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);
我的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];
}