【问题标题】:Angular + Capacitor: appStateChange listener not workingAngular + Capacitor:appStateChange 监听器不工作
【发布时间】:2021-12-04 00:27:00
【问题描述】:

为了解决 KPI,我尝试在用户关闭应用程序(离子/电容器/角度)时使用 Firebase SDK 生成 logEvent。但是我在尝试进入 appStateChange 监听器时遇到了很多麻烦(这是在我的 app.component.tsngOnInit 方法中创建的)。

由于官方的电容器后台任务插件被停用,我一直在使用这个社区插件,权利here,就像官方的一样

  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 等......它们都没有像我预期的那样工作(没有进入处理程序)。如果有人能帮我弄清楚这个,我将不胜感激。

【问题讨论】:

    标签: angular typescript firebase ionic-framework capacitor


    【解决方案1】:

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

    【讨论】:

      猜你喜欢
      • 2013-07-12
      • 1970-01-01
      • 2012-07-31
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-05-18
      • 2012-06-17
      • 1970-01-01
      相关资源
      最近更新 更多