Cloud Functions for Firebase: can you detect app uninstall?

泄露秘密 提交于 2020-01-20 02:48:28

问题


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?


回答1:


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
});


来源:https://stackoverflow.com/questions/45744408/cloud-functions-for-firebase-can-you-detect-app-uninstall

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!