Ionic run function before app closes

前端 未结 2 1303
离开以前
离开以前 2021-02-20 11:52

Is there some kind of function that I can call that listens to whether the app is about to exit, or close or go into the background.. Basically any event that means \"the user h

相关标签:
2条回答
  • 2021-02-20 11:55

    This code works in ionic2 native app exit and in the browser as well. In the browser, this happens when the URL reload button is pressed or the browser tab is closed.

    platform.pause.subscribe(e => {
      this.OptionsSave();
    });
    
    window.addEventListener('beforeunload', () => {
      this.OptionsSave();
    });
    
    0 讨论(0)
  • 2021-02-20 12:12

    You can check this events list from Cordova docs:

    https://cordova.apache.org/docs/en/5.4.0/cordova/events/events.html

    In particular Pause event:

    The event fires when an application is put into the background.

    document.addEventListener("pause", yourCallbackFunction, false);

    0 讨论(0)
提交回复
热议问题