ログインに使用するナビゲーション グループがあります。ユーザーが正常にログインすると、アプリはナビゲーション グループを閉じ (navGroup.close を使用して、これが破棄されたと仮定します)、タブ グループを作成します。ユーザーがログアウトすると、タブグループが閉じられ、ナビゲーション グループが再度作成されます。問題は、facebook のログイン ボタン (ナビゲーション グループにある) が 1 回目は navgroup が作成されたときに問題なく動作することですが、2 回目は「ログイン」リスナーが 2 回実行され、3 回目は 3 回実行されるなどです。このバグを生成する単純化されたコードを次に示します。
app.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');
loginFBC.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();
});