Detect if my app is closed


#1

Hello, everyone!

I’m trying to build my ionic app and I have to unsubscribe from push notifications after I exit it.

I wonder if there is a way to get the event of closing my app in apple devices?


#2

There’s no such event. It would be considered a security flaw.


#3

Closest you can get is event that tells you when the App has entered the background. Put this into your .run():

    //handle Cordova resume (enter foreground) and pause (enter background events)
    $ionicPlatform.on('resume', function() {
        
    });

    $ionicPlatform.on('pause', function() {
        //Do something here on entering background
    });

#4

i’ve done this to handle the pause event

document.addEventListener('deviceready', function(){
      document.addEventListener('pause', function(){
         //Do something here on entering background
        }, false);
}, false);

and it worked. i think it’s necessary to put our pause event inside a deviceready event.


#5

Why would it be a security flaw?