我有一个用于登录的导航组。如果用户成功登录,则应用程序将关闭导航组(使用 navGroup.close 我假设它已被破坏)并创建一个选项卡组。当用户注销时,选项卡组关闭并再次创建导航组。问题是 facebook 登录按钮(位于导航组上)在第一次创建导航组时工作正常,但第二次执行“登录”侦听器 2 次,3d 时间执行 3 次,依此类推。这是生成此错误的简化代码:
应用程序.js
Ti.App.Properties.setString("fbAccess","login");
Ti.Facebook.appid = 'xxxxxxxxxx';
Ti.Facebook.permissions = ['publish_stream','offline_access','email'];
//Ti.Facebook.forceDialogAuth = false;
Ti.include('preLogin.js');
登录FBC.js
Ti.Facebook.addEventListener('login', function(e) {
Ti.API.info("inside login");
if ((e.success) && (Ti.App.Properties.getString("fbAccess")=="login")) {
Ti.API.info("inside if");
navGroup.close();
Ti.include('preLogin.js');
}});
preLogin.js
var buttonLoginFB = Titanium.UI.createButton({
top: "90%",
width: "70%",
height: "12%"});
var preLoginWin = Titanium.UI.createWindow({
titleImage:'/icons/logoForBar.png',
title:"Back",
backgroundColor:'#fff',
barColor:'00aeef',
});
var buttonLogin = Titanium.UI.createButton({
title: 'Login',
top: "30%",
width: "70%",
height: "12%",
opacity:1
});
var buttonRegister = Titanium.UI.createButton({
title: 'Register',
top: "60%",
width: "70%",
height: "12%",
opacity:1
});
var navGroup = Ti.UI.iPhone.createNavigationGroup({
window:preLoginWin
});
preLoginWin.add(buttonLogin,buttonRegister,buttonLoginFB);
var main = Ti.UI.createWindow();
main.add(navGroup);
main.open();
Ti.include('/loginFBC.js');
//include the preLoginC.js that holds the code for the buttons listeners
Ti.include('/preLoginC.js');
和 preLoginC.js
buttonLoginFB.addEventListener("click", function(e) {
Ti.API.info("button");
Ti.Facebook.logout();
Ti.Facebook.appid = 'xxxxxxxxxxx';
Ti.Facebook.permissions = ['publish_stream','offline_access','email'];
//Ti.Facebook.forceDialogAuth = false;
Ti.Facebook.authorize();
});