首页 > 解决方案 > 如何处理离子中的应用程序退出?

问题描述

我一直在使用平台的暂停和恢复事件,如下面的代码,但我想在用户关闭应用程序而不是在后台使用应用程序时处理退出事件。

this.platform.ready().then(() => {

      if (this.platform.is('cordova')){
        this.platform.pause.subscribe(() => {
          this.stopTimer();
        });
       }
});

有没有办法获得任何帮助。

标签: cordovaionic-frameworkionic3

解决方案


对于浏览器,您可以尝试这样的操作,直接访问窗口事件:

window.addEventListener('beforeunload', () => {
  this.OptionsSave();
});

推荐阅读