Ios 科尔多瓦:如何检测Facebook插件已加载?

Ios 科尔多瓦:如何检测Facebook插件已加载?,ios,cordova,phonegap-plugins,cordova-plugins,Ios,Cordova,Phonegap Plugins,Cordova Plugins,我正在用Cordova开发一个iOS应用程序,我正在使用Facebook connect插件进行身份验证 我的问题是:有时候Facebook插件加载得不够早,所以FB身份验证不会采用原生方式,而是通过一种应用程序内浏览器弹出窗口 有没有办法检测Fb插件已完成加载 谢谢我认为你应该使用facebook phonegap插件作为身份验证 下载并安装到您的cordova项目中 然后确保项目中有此脚本 cdv-plugin-fb-connect.js facebook-js-sdk.js 之后,将此

我正在用Cordova开发一个iOS应用程序,我正在使用Facebook connect插件进行身份验证

我的问题是:有时候Facebook插件加载得不够早,所以FB身份验证不会采用原生方式,而是通过一种应用程序内浏览器弹出窗口

有没有办法检测Fb插件已完成加载


谢谢

我认为你应该使用facebook phonegap插件作为身份验证

下载并安装到您的cordova项目中

然后确保项目中有此脚本

cdv-plugin-fb-connect.js
facebook-js-sdk.js
之后,将此代码粘贴到主脚本中

if ((typeof cordova == 'undefined') && (typeof Cordova == 'undefined')) alert('Cordova variable does not exist. Check that you have included cordova.js correctly');
if (typeof CDV == 'undefined') alert('CDV variable does not exist. Check that you have included cdv-plugin-fb-connect.js correctly');
if (typeof FB == 'undefined') alert('FB variable does not exist. Check that you have included the Facebook JS SDK file.');
FB.Event.subscribe('auth.login', function(response) {
    //alert('auth.login event');
});
FB.Event.subscribe('auth.logout', function(response) {
    //alert('auth.logout event');
});
FB.Event.subscribe('auth.sessionChange', function(response) {
    //alert('auth.sessionChange event');
});
FB.Event.subscribe('auth.statusChange', function(response) {
    //alert('auth.statusChange event');
});

function getSession() {
    alert("session: " + JSON.stringify(FB.getSession()));
}

function getLoginStatus() {
    FB.getLoginStatus(function(response) {
        if (response.status == 'connected') {
            alert('logged in');
        } else {
            alert('not logged in');
        }
    });
}
var friendIDs = [];
var fdata;

function logout() {
    FB.logout(function(response) {
        alert('logged out');
        window.location.replace("#login");
    });
}

function login() {
    FB.login(

    function(response) {
        if (response.authResponse) {
            alert('logged in');
            FB.api('/me', function(me) {
                if (me.id) {
                                    localStorage.id = me.id;
                    localStorage.email = me.email;
                    localStorage.name = me.name;
                    window.location.replace("#home");
                }
                else {
                    alert('No Internet Connection. Click OK to exit app');
                    navigator.app.exitApp();
                }
            });
        } else {
            alert('not logged in');
        }
    }, {
        scope: "email"
    });
}

document.addEventListener('deviceready', function() {
    try {
        //alert('Device is ready! Make sure you set your app_id below this alert.');
        FB.init({
            appId: "appid",
            nativeInterface: CDV.FB,
            useCachedDialogs: false
        });
        document.getElementById('data').innerHTML = "";
    } catch (e) {
        alert(e);
    }
}, false);

使用
login()
登录。享受

如果插件在测试应用程序时加载失败,日志中必须有一个条目

另外,看起来您正在使用facebook API、phonegap和其他本机插件总是在中提供的推荐插件之后加载

它还按照您在XML文件中提到的顺序加载

<feature name="org.apache.cordova.facebook.Connect">
    <param name="ios-package" value="FacebookConnectPlugin" />
</feature>
最后添加按钮以调用插件,如下所示:

<body onload="onBodyLoad()"> 
     <h1>Hey, it's Cordova!</h1> 
      <button onclick="callYourPlugin('success');">Click to invoke the Native Plugin with an SUCCESS!</button> 
      <button onclick="callYourPlugin('error');">Click to invoke the Native Plugin with an ERROR!</button> 
</body> 

嘿,我是科尔多瓦!
单击以成功调用本机插件!
单击以调用本机插件,但出现错误!

我觉得这个方法很容易调用任何插件,你也可以查看更多信息。

让我知道,这样我可以帮助你。我可能应该更清楚地描述我的问题。我实际上正在使用这个插件。大多数情况下,它运行良好。但有时它会通过浏览器弹出窗口。
function callYourPlugin( returnSuccess ) { 
    YourPlugin.callNativeFunction( YourPluginResultHandler, YourPluginErrorHandler, returnSuccess ); 
} 
function YourPluginResultHandler (result) { 
   alert("SUCCESS: \r\n"+result ); 
} 
function YourPluginErrorHandler (error) { 
   alert("ERROR: \r\n"+error ); 
} 
<body onload="onBodyLoad()"> 
     <h1>Hey, it's Cordova!</h1> 
      <button onclick="callYourPlugin('success');">Click to invoke the Native Plugin with an SUCCESS!</button> 
      <button onclick="callYourPlugin('error');">Click to invoke the Native Plugin with an ERROR!</button> 
</body>