Angular + 电容器:appStateChange 侦听器不工作

Angular + Capacitor: appStateChange listener not working

为了解决 KPI,我尝试在用户关闭应用程序时使用 Firebase SDK 生成一个 logEvent(Ionic/Capacitor/Angular)。但是我在尝试进入那个 appStateChange 侦听器时遇到了很多麻烦(这是在我的 app.component.tsngOnInit 方法中创建的)。

As the official Capacitor Background Task Plugin was deactivated, i've been using this community plugin right here, that acts just like the official one

  import { BackgroundTask } from '@robingenz/capacitor-background-task';

  App.addListener('appStateChange', async ({ isActive }) => {
       // It isn't getting here

       if (isActive)
         return;
       
       // When the app is running at the background

       const taskId = await BackgroundTask.beforeExit(async () => {
            console.log('Sending app_close event to Firebase')

            await this.firebaseAnalyticsService.logEvent('app_close', {
              lastScreenName: this.firebaseAnalyticsService.getCurrentScreenName(),
            });

            BackgroundTask.finish({ taskId });
       });
  })

  

我也尝试通过其他方法来处理这个问题,使用 cordova 插件,window.beforeUnload,等等...None 其中的工作如我所料(没有进入处理程序).如果有人能帮我解决这个问题,我将不胜感激。

已解决!我的解决方案是增加 Capacitor 版本并删除后台任务插件,因为我的意图不需要它。