Platform Events for "pause" and "resume" Not Emitting?

We are attempting to use the pause and resume events emitted by Platform in Ionic 2.

We are not seeing these events emitted.

Here is the code we are using, any feedback would be appreciated.

platform.ready().then(() => {
    StatusBar.overlaysWebView(false);
    StatusBar.backgroundColorByHexString("#622B7D");
    document.addEventListener("pause", function() {
        // not firing
        console.log("paused")
    }, false);
    document.addEventListener("resume", function() {
        // not firing
        console.log("resumed")
    }, false);
});

Hi, the following code worked for me.

constructor( private platform: Platform ) {
    platform.ready().then(() => {    
        this.platform.pause.subscribe(() => {
            console.log('[INFO] App paused');
        });

        this.platform.resume.subscribe(() => {
            console.log('[INFO] App resumed');
        });
    });

Hope it helps.

3 Likes

The above code did not work for me.

could you provice ionic info?

Sorry, I was trying it in PWA, as per the following issue it won’t work on web.

Using the function without fat arrow changes the scope, if you use fat arrow notation instead , it shoud work, please see below
this.platform.ready().then(
()=>{ document.addEventListener(“pause”, ()=> {
// not firing
console.log(“paused”)
}, false);
document.addEventListener(“resume”, ()=> {
// not firing
console.log(“resumed”)
}, false);
});