Cloud Functions for Firebase:您能检测到应用卸载吗? [英] Cloud Functions for Firebase: can you detect app uninstall?

查看:17
本文介绍了Cloud Functions for Firebase:您能检测到应用卸载吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以在用户卸载应用时触发一个Cloud Function,以便我们清理匿名用户实时数据库条目?

Is it possible to trigger a Cloud Function when the user uninstalls the app, so that we can clean up the anonymous user realtime database entry?

推荐答案

您可以将 Android 应用卸载检测为 自动收集的名为 app_remove 的 Analytics 事件.然后您可以触发云函数在该事件发生时运行.您还需要使用 Firebase Admin SDK 来访问数据库.查看一些 Cloud Functions for Firebase GitHub 示例,查看使用 Analytics 触发器和使用管理 SDK.该函数可以像这样工作:

You can detect app uninstall for Android as an automatically collected Analytics event called app_remove. Then you could trigger a Cloud Function to run when that event occurs. You would also need to use the Firebase Admin SDK to access the database. Check out some of the Cloud Functions for Firebase GitHub samples to see examples of using Analytics triggers and using the Admin SDK. The function could work something like this:

exports.appUninstall = functions.analytics.event('app_remove').onLog(event => {
  const user = event.user; // structure of event was changed            
  const uid = user.userId; // The user ID set via the setUserId API.

  // add code for removing data
});

这篇关于Cloud Functions for Firebase:您能检测到应用卸载吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆