我正试图在用户离开应用程序时执行一个方法.我尝试了一切:
ionViewWillUnload() {
console.log("Wlill unload");
this.leaveRoom();
}
onDestroy() {
console.log("DESTROY");
this.leaveRoom();
}
ionViewWillLeave() {
this.leaveRoom();
}
Run Code Online (Sandbox Code Playgroud)
不幸的是,当用户关闭应用程序或用户刷新页面时,它们不会被执行.
任何的想法?
The*_*eal 12
进口平台:
import { Platform } from 'ionic-angular';
将平台添加到构造器:
constructor(public navCtrl: NavController, platform: Platform)
订阅该平台pause并resume:
platform.ready().then(() => {
this.platform.pause.subscribe(() => {
console.log('[INFO] App paused');
});
this.platform.resume.subscribe(() => {
console.log('[INFO] App resumed');
});
});
Run Code Online (Sandbox Code Playgroud)