当用户离开应用程序时,我试图执行一种方法。我什么都试过了
ionViewWillUnload() {
console.log("Wlill unload");
this.leaveRoom();
}
onDestroy() {
console.log("DESTROY");
this.leaveRoom();
}
ionViewWillLeave() {
this.leaveRoom();
}不幸的是,当用户关闭应用程序或用户刷新页面时,它们不会被执行。
有什么想法吗?
发布于 2016-12-29 12:55:39
import { Platform } from 'ionic-angular';constructor(public navCtrl: NavController, platform: Platform)pause和resume:
Platform.ready().then() => {this.platform.pause.subscribe()) => { console.log('INFO应用暂停“);};this.platform.resume.subscribe(() => { console.log('INFO应用程序恢复”);});};发布于 2016-12-29 12:09:48
我想在这里可以找到你在找什么:
http://cordova.apache.org/docs/en/6.x/cordova/events/events.html#endcallbutton
具体而言,这一活动:
function onEndCallKeyDown() {
// Handle the end call button
}为了使事件正常工作,您必须首先声明此侦听器:
document.addEventListener("endcallbutton", onEndCallKeyDown, false);onPause事件:
document.addEventListener("pause", onPause, false);
function onPause() {
// Handle the pause event
}onResume事件
document.addEventListener("resume", onResume, false);
function onResume() {
// Handle the resume event
}希望能帮上忙!
https://stackoverflow.com/questions/41379376
复制相似问题