I want to call an api when the app closes/terminates in anyway it can. I am using react with ionic. i tried using background runner by capacitor but its not able to locate the runner file. I also tried the cordova pugin which gives didlaunch and wilterminate events but this doesn’t work at all.
I’m pretty sure there’s no reliable way to do this in React because it’s running in a webview, which doesn’t have a way to determine if the app has been terminated.
If you’re having trouble getting capacitor’s background runner working, I would ask about that on the capacitor forum.
To run a function when your app closes, you can use lifecycle methods. For example, in Android, use onStop()
or onDestroy()
to call your API. In iOS, you can use applicationWillTerminate()
. Make sure your API call is asynchronous to avoid blocking the app shutdown process.
Can you share the way to access these said lifecycle methods.