Reputation: 24492
I'm trying to execute a method when the user leaves the app. I tried everything:
ionViewWillUnload() {
console.log("Wlill unload");
this.leaveRoom();
}
onDestroy() {
console.log("DESTROY");
this.leaveRoom();
}
ionViewWillLeave() {
this.leaveRoom();
}
Unfortunetly they are not executed when user closes the app or when the user refresh the page.
Any idea?
Upvotes: 4
Views: 4836
Reputation: 24492
Import Platform:
import { Platform } from 'ionic-angular';
Add Platform to the constuctor:
constructor(public navCtrl: NavController, platform: Platform)
subscribe to the platform pause
and resume
:
platform.ready().then(() => {
this.platform.pause.subscribe(() => {
console.log('[INFO] App paused');
});
this.platform.resume.subscribe(() => {
console.log('[INFO] App resumed');
});
});
Upvotes: 13
Reputation: 802
I think what are you looking for can be found here:
http://cordova.apache.org/docs/en/6.x/cordova/events/events.html#endcallbutton
Specifically this event:
function onEndCallKeyDown() {
// Handle the end call button
}
In order to make the event work you have to declare this listener first:
document.addEventListener("endcallbutton", onEndCallKeyDown, false);
onPause Event:
document.addEventListener("pause", onPause, false);
function onPause() {
// Handle the pause event
}
onResume event
document.addEventListener("resume", onResume, false);
function onResume() {
// Handle the resume event
}
Hope it helps!
Upvotes: 0