cordova-plugin-lifecycle-events-extra

    1.1.0 • Public • Published

    cordova-plugin-lifecycle-events-extra

    Cordova Plugin for Extra App Lifecycle Events, including Terminate and Destroy.

    Based heavily on:

    Similar plugins which may better meet one's requirements include:

    Installation

    cordova plugin add cordova-plugin-lifecycle-events-extra

    Warning! You should not call any interactive Javascript in the event handler! This includes alert() and any other interaction with the user. Ensure that your handler is "headless".

    In your JS event handler, you should strong consider wrapping your JS code in setTimeout. Otherwise, AJAX calls, for example, will not work.

    Included Additional Lifecycle Events

    • willterminate = (UIApplicationWillTerminateNotification)[]
    • didlaunch = (UIApplicationDidFinishLaunchingNotification)[https://developer.apple.com/documentation/uikit/uiapplicationdidfinishlaunchingnotification?language=objc]

    Usage

    Only after the deviceready event has fired, add these event listeners within the deviceready handler's function body:

    iOS

    Warning! iOS does not broadcast any event upon termination when the app is already in the background!

     document.addEventListener("deviceready", function (event1) {
     
         document.addEventListener('willterminate', function (event2) {
            /* iOS cordova quirk */
            setTimeout(function() {
                console.log('terminate event has fired.');
                // more JS here!
           }, 0);
        });
     
     }, false);

    Android

    document.addEventListener('destroy', function () {
        // your JS code here!
    });

    Browser Platform

    Just register a beforeunload event on the body:

    window.addEventListener("beforeunload", function (event) {
      event.preventDefault();
     
      myUnloadFunction("erase all the things!");
     
      return '';
    });

    Install

    npm i cordova-plugin-lifecycle-events-extra

    DownloadsWeekly Downloads

    0

    Version

    1.1.0

    License

    MIT

    Unpacked Size

    14.1 kB

    Total Files

    9

    Last publish

    Collaborators

    • mgatto