Already tried :
App.exitApp(), navigator.app.exitApp(), navigator[‘app’].exitApp(), ionic.platform.exitApp()… doesn’t work
my code:
import { Injectable } from '@angular/core';
import { AlertController, NavController, Platform } from '@ionic/angular';
import { Router } from '@angular/router';
import { App } from '@capacitor/app';
@Injectable({
providedIn: 'root'
})
export class BackButtonExitService {
constructor(
private platform: Platform,
private router: Router,
private navCtrl: NavController,
private alertController: AlertController
) { }
init(){
this.platform.backButton.subscribeWithPriority(6666666666666666, async ()=>{
const currentUrl = this.router.url;
if(currentUrl === '/home'){
const alert = await this.alertController.create({
header: 'Quer Sair?',
buttons: [
{
text: 'Não',
role: 'cancel'
},
{
text: 'Sim',
role: 'confirm',
handler: () => {
window.close();
},
},
],
});
await alert.present();
}else if(currentUrl === '/'){
const alert = await this.alertController.create({
header: 'Quer Sair?',
buttons: [
{
text: 'Não',
role: 'cancel'
},
{
text: 'Sim',
role: 'confirm',
handler: () => {
window.close();
},
},
],
});
await alert.present();
}
else{
this.navCtrl.back();
}
})
}
}
ionic version is the newest (5)
helmp me…