如果用户已经授权应用程序,我有一个FB.getLoginStatus函数可以绕过登录功能:
FB.getLoginStatus(function(response) {
if (response.status === 'connected') {
userID = response.authResponse.userID;
accessToken = response.authResponse.accessToken;
$.mobile.pageContainer.pagecontainer('change' , '#homepage');
navigator.geolocation.getCurrentPosition(onSuccess, onError);
} else if (response.status === 'not_authorized') {
$.mobile.pageContainer.pagecontainer('change' , '#login');
} else {
$.mobile.pageContainer.pagecontainer('change' , '#login');
}
});
它的工作原理是它会检查登录状态,但它会在跳转到主屏幕之前快速闪烁登录屏幕。有没有办法可以完全避免闪烁登录界面,只是在连接用户时加载主屏幕?
答案 0 :(得分:0)
是的,有一个可行的解决方案:
$(document).on('pagebeforechange', function(e, data){
var to = data.toPage,
from = data.options.fromPage;
if (typeof to === 'string') {
var u = $.mobile.path.parseUrl(to);
to = u.hash || '#' + u.pathname.substring(1);
if (from) from = '#' + from.attr('id');
if (from === '#index' && to === '#second') {
alert('Can not transition from #index to #second!');
e.preventDefault();
e.stopPropagation();
// remove active status on a button, if transition was triggered with a button
$.mobile.activePage.find('.ui-btn-active').removeClass('ui-btn-active ui-shadow').css({'box-shadow':'0 0 0 #3388CC'});
}
}
});
您需要在此处添加另一层检查:
if (from === '#index' && to === '#second') {
您需要做的就是检查用户是否通过Facebook授权并使用 changePage()功能以编程方式重定向他。
详细了解 here 。
我忘了,这个例子在你的情况下可能不起作用,因为如果你在开始时检查它你将没有目标页面,因为你在这里确定哪个页面是第一个:登录页面或主页面。
在这种情况下,此代码将为您提供帮助:
$(document).on('pagebeforechange', function(e, data){
var to = data.toPage;
if (typeof to === 'string') {
var u = $.mobile.path.parseUrl(to);
to = u.hash || '#' + u.pathname.substring(1);
if (to === '#second') {
alert('Can not transition the page #second!');
e.preventDefault();
e.stopPropagation();
// remove active status on a button, if transition was triggered with a button
$.mobile.activePage.find('.ui-btn-active').removeClass('ui-btn-active ui-shadow').css({'box-shadow':'0 0 0 #3388CC'});
}
}
});