适用于Firebase的Cloud Functions:您可以检测到应用程序卸载吗? [英] Cloud Functions for Firebase: can you detect app uninstall?

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

问题描述

用户卸载应用程序时是否可以触发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?

推荐答案

您可以将触发云功能,以在该事件发生时运行发生.您还需要使用 Firebase管理SDK 来访问数据库.查看一些 Firebase GitHub示例的云函数,以查看使用Analytics触发器和使用Admin 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
});

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

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