如何解决用户在应用程序中处于非活动状态一段时间后,Ionic 3重定向?
我们如何检测用户在离子应用程序中处于非活动状态,以便我们可以再次将其重定向到登录页面。
根据韦斯利答案
// idle logout timer set to 10 second
public idlelogoutTimer: number = 10000;
// First execute the timer and wait for hostListener
onInit() {
this.restartIdlelogoutTimer();
}
// Whenever users touch action occure this function will execute.
@HostListener('touchstart')
onTouchStart() {
this.restartIdlelogoutTimer();
}
// First this will clear timeout then again setTimeout fun and counting start again,After specific time if user did not active then log out function will execute.
restartIdlelogoutTimer() {
clearTimeout(this.idlelogoutTimer);
this.idlelogoutTimer = setTimeout(()=>{
this.logoutUser();
},60000);
}
logoutUser() {
// your logout logic here
}
解决方法
如何?
将超时设置为您认为某人“空闲”的任何时间。然后听“ touchstart”事件,并在每次用户触摸屏幕时触发超时以重新启动。
在app.component.ts
中@HostListener('touchstart')
onTouchStart() {
this.restartIdleLogoutTimer();
}
idleLogoutTimer;
OnInit() {
restartIdleLogoutTimer();
}
restartIdleLogoutTimer() {
clearTimeout(this.idleLogoutTimer);
this.idleLogoutTimer = setTimeout(()=>{
this.logoutUser();
},60000);
}
logoutUser() {
// your logout logic here
}
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。