在ionic3中,如果想退出应用程序,大部分的写法都是
import { Platform } from 'ionic-angular';
constructor(
private platform: Platform,
) {
this.exit()
}
exit(){
this.platform.registerBackButtonAction(() => {
this.platform.exitApp();
});
}
在Ionic4/5中写法如下
import { Platform } from '@ionic/angular';
this.platform.backButton.subscribe(() => {
navigator['app'].exitApp();
});
在Ionic7中写法如下
import { Platform } from '@ionic/angular';
import { App } from '@capacitor/app';
this.platform.backButton.subscribe(() => {
App.exitApp();
});