Ionic7退出应用程序的写法
kelvin 发布于 2024-04-24

在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();
    });
kelvin
关注 私信
文章
92
关注
0
粉丝
0