Detect app inactive / active status

Hi, currently I want to log the time that user spend on my app, and I referred the following code to record the timestamp.

this.platform.ready().then(() => {
 this.platform.pause.subscribe(() => {        
     console.log('****APP PAUSED**** => log end time');
 });  
 this.platform.resume.subscribe(() => {      
     console.log('****APP RESUMED**** => log start time');
 });
});

It can work as expected. However it cannot handle the case when user force quit the app, it will not trigger the pause event, which means it cannot logged the “paused” time.

After read the log on iOS, I find out that there is an event that fires and print a message(APP INACTIVE) everytime when the app is not in active status (like hide in background or when showing multi-task panel).

I’d like to ask is there anyway that can bind some funtions to that event to better handle the app status? And I can log the end time even when user force quit the app. Thanks in advance.

Sloved this issue by using capactior plugin.

https://capacitorjs.com/docs/apis/app