我通过创建脚本制作了一个cordova项目并创建了一个插件。但是,由于某种原因,每当我发送插件结果时,都不会调用 JS 回调。
我检查了callbackID。它充满了(看似)有效的回调。我的插件映射没问题,本机代码被执行并且没有错误。
我不知道为什么没有触发回调..
我的 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];
}