【发布时间】:2021-12-04 00:27:00
【问题描述】:
为了解决 KPI,我尝试在用户关闭应用程序(离子/电容器/角度)时使用 Firebase SDK 生成 logEvent。但是我在尝试进入 appStateChange 监听器时遇到了很多麻烦(这是在我的 app.component.ts 的 ngOnInit 方法中创建的)。
由于官方的电容器后台任务插件被停用,我一直在使用这个社区插件,权利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