离子电容器硬件返回按钮自动关闭应用程序

问题描述:

我目前的设置是:

@capacitor/core: 3.0.0,@ionic-native/core: 5.0.7

@capacitor/core: 3.0.0, @ionic-native/core: 5.0.7

我正在尝试更改我的应用程序的行为,以便不关闭应用程序,而是返回导航堆栈.据我所知,在我将 Capacitor 升级到 3.0.0 之前,Android 设备上的硬件后退按钮不会自动关闭应用程序

I'm trying to change the behavior of my app to not close the app, but go back in the navigation stack. To my knowledge, the hardware back button on Android devices did not automatically close the app until I upgraded Capacitor to 3.0.0

让我感到困惑的是,我如何拥有处理后退按钮功能的绝对 0 代码,并且从我在网上搜索的所有内容显示后退按钮默认不执行任何操作,而不是自动关闭应用程序作为默认值(如我的似乎在做).我已经搜索了所有与平台"、backButton"和App.Exit"有关的项目文件.并且无法找到任何可能导致应用关闭的代码.

What is confusing me though, is how I have absolutely 0 code for handling the back button functionality, and from everything I'm searching online shows the back button doing nothing by default, not automatically closing the app as the default (as mine seems to be doing). I've searched all the project files for anything to do with "platform", "backButton", and "App.Exit" and was unable to find any code that may be causing the app to close.

我尝试使用以下代码订阅后退按钮按下事件,但从未运行过.应用程序关闭而不是显示警报对话框.我已将优先级从 0、10 和 99(Ionic 文档中列出的所有优先级)更改为

I've tried subscribing to the back button press event using the below code and it is never ran. The app closes instead of showing the alert dialog. I've changed the priority from 0, 10, and 99 (all priorities listed in the Ionic documentation)

this.platform.backButton.subscribeWithPriority(10, () => {
  alert('Back button pressed!');
});

所以,意识到这一点后我觉得有点傻,但那是因为我不得不运行下面的命令,因为我显然在升级时没有更新它们不久前的电容器.确保您的所有插件都已完全更新,您的可能与我的不同.

So, I feel a bit dumb after realizing this, but it is because I had to run the below commands, because I apparently didn't update them when upgrading Capacitor a while back. Make sure all of your plugins are fully updated, yours may be different than mine.

npm install @capacitor/app
npx cap sync