简体   繁体   English

强制在jQuery Mobile / Phonegap应用重启时登录

[英]Force login on jQuery Mobile/Phonegap app restart

I've got an app running jQuery 1.9.1, jQuery Mobile 1.4.2 and Phonegap 3.4.0. 我有一个运行jQuery 1.9.1,jQuery Mobile 1.4.2和Phonegap 3.4.0的应用程序。

It has a login screen so that when you first open the app, you input your info, it does an AJAX check and if all is well, stores your info and moves you past that page. 它具有一个登录屏幕,以便您首次打开该应用程序时,输入您的信息,然后进行AJAX检查,如果一切正常,则存储您的信息并将您移至该页面之外。

The ideal scenario, is that everytime the app is sent to the background (the user goes home or switches apps), and then restarts the app they have to login again. 理想的情况是,每次将应用程序发送到后台(用户回家或切换应用程序),然后重新启动应用程序时,他们都必须再次登录。

Currently I am accomplishing this in iOS by setting the 目前,我正在iOS中通过设置

<preference name="exit-on-suspend" value="true" />

preference in my config.xml . 我的config.xml首选项。 I am accomplishing the same thing in Android by using navigator.app.exitApp(); 我正在通过使用navigator.app.exitApp();在Android中完成相同的操作navigator.app.exitApp(); in a pause event listener. pause事件监听器中。

This works well enough usually, but some older versions of android have a weird problem. 通常,这通常效果很好,但是某些较旧的android版本存在一个奇怪的问题。 While going home and restarting the app bring you to the login page, you can just hit the back button and it takes you to the last page you were on before you quit, and you are still logged in. I also have a function that destroys all user variables (rendering all pages useless) when the app pauses, but that also seems to be ignored. 回家并重新启动应用程序时,您将进入登录页面,您只需单击“后退”按钮,即可将您带到退出前的最后一页,并且仍在登录。我还有一个销毁功能应用暂停时所有用户变量(使所有页面无效),但这似乎也被忽略了。 On older versions of Android (2.3 specifically), it seems that they are ignoring the pause event listener. 在旧版的Android(特别是2.3版)上,似乎他们忽略了pause事件监听器。

How do I fix that, or is there an all around better way of forcing login on restart? 如何解决该问题,还是有一种更好的强制重新启动登录的方法?

Without knowing what other requirements you have or what behaviors you might expect from the home page, you could capture the back button event and prevent it from going anywhere. 在不知道您还有其他要求或从首页可能期望什么行为的情况下,您可以捕获“后退”按钮事件并阻止其继续进行。

//set a bit or note that you are on the login page
var onHome = true;

...

document.addEventListener("backbutton", backButtonTap, false);

function backButtonTap(e) {
    if(onHome) {
      e.preventDefault();
      alert('Please Login');
    }
}

Certainly not the only or perhaps the best way to handle it since the user appears to stay logged in, which you say is supposed to be wiped out, but it should at least prevent navigating away from the login page and going back. 当然,这不是唯一或最好的处理方式,因为用户似乎保持登录状态(应该说已经消失了),但是它至少应防止导航离开登录页面并返回。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM