我是PhoneGap版本的新手,我尝试编写一个带有登录按钮的简单应用程序。在PhoneGap构建文档中,我发现添加此插件非常简单
index.html
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="http://code.jquery.com/mobile/1.3.0/jquery.mobile-1.3.0.min.css" />
<script src="http://code.jquery.com/jquery-1.8.2.min.js"></script>
<script src="http://code.jquery.com/mobile/1.3.0/jquery.mobile-1.3.0.min.js"></script>
<script src="http://crypto-js.googlecode.com/svn/tags/3.1.2/build/rollups/sha256.js"></script>
<script src="http://crypto-js.googlecode.com/svn/tags/3.1.2/build/components/enc-base64-min.js"></script>
<script src="js/facebookConnectPlugin.js"></script>
<script src="js/jq.js"></script>
</head>
<body>
<div data-role="page" id="contenuto">
<a href="index.html" data-role="button" class='bt_loginProprietario'>Login</a>
<a href="index.html" data-role="button" class='bt_loginFacebook'>Login con facebook</a>
</div>
</body>
</html>
jq.js
function loginFacebook(){
facebookConnectPlugin.login( ["email"],
function (response) { alert(JSON.stringify(response)) },
function (response) { alert(JSON.stringify(response)) };
};
$(document).ready(function(){
$('#contenuto').on('click','.bt_loginFacebook',function(){
loginFacebook();
});
});
在PG构建中我看到插件正确加载但是当我尝试在我的Android手机上执行应用程序时,我点击按钮没有任何反应。我试图在我的浏览器中执行并收到错误&#34; cordova未定义
对于帮助这是我的第一篇文章,我不明白出了什么问题更新 根据你的建议我的jq.js现在有这个代码:
document.addEventListener("deviceready", function(){
$('#contenuto').on('click','.bt_loginFacebook',function(){
loginFacebook();
});
});
但是当我按下按钮没有任何反应时,我在Chrome控制台中看到一个错误,表示未定义cordova
帮助请
答案 0 :(得分:0)
This is very common for person new to cordova/phonegap.
You are using a facebook plugin for phonegap. Phonegap REQUIRES that you wait until the deviceready event fires before you access any phonegap or 3rd-party plugin services. This blog post explains in more detail.
FYI – Cordova events must be run after deviceReady
http://www.raymondcamden.com/2015/07/15/fyi-cordova-events-must-be-run-after-deviceready