如何在Firebase中按应用程序版本阻止用户 [英] How to block users by app version in Firebase

查看:69
本文介绍了如何在Firebase中按应用程序版本阻止用户的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个将Firebase用于一般聊天室的Android应用.用户输入昵称并开始聊天.

I have an Android app that use Firebase for general chat room. Users enter their nickname and start to chat.

关于实现没有问题,我的应用程序运行良好.但是问题在于数据使用情况.由于实施错误,数据使用率过高.

There is no problem about implementation, my application works well. But the problem is about data usage. Data usage was too high because of wrong implementation.

在应用版本14中

我正在获取聊天室中的所有数据,然后显示最后100个.这种情况导致Firebase数据的使用率很高.每天有1-2GB的下载量可供2k用户使用.实际上应该更少.

I was fetching all data in chat room, then show the last 100. This situation causes high usage in firebase data. There was daily 1-2GB download usage for 2k users. In fact it should be less.

然后,一周前,我学习了 limitToLast(x)函数.

Then, a week ago, I learned limitToLast(x) function.

https://firebase.google.com/docs/database/admin /retrieve-data

然后,我决定更新我的应用程序.

Then I decided to update my app.

在应用版本15中

我在代码中的必需行中添加了 limitToLast(100)函数. 现在,我的15-ver用户没有问题.每天的数据使用量已降至每天100MB.

I added limitToLast(100) function to required lines in my code. Now, there is no problem for my 15-ver users. Daily data usage dropped to 100MB per day.

最近,我的数据使用量每天增加到300-400MB.

Recently, my data usage rised to 300-400MB, daily.

这是因为您知道有数百个apk网站.

This is because you know there are hundreds of apk sites.

1-这些APK网站并不总是包含最新版本.

1- These apk sites do not always contain last version.

2-有些用户没有更新我的应用.

2- There are some users do not update my app.

结果,有一些用户使用15版以下的我的应用.这些用户导致数据使用问题,因为在版本14中,代码存在问题,并导致数据使用问题.

As a result, there are some users that uses my app below 15 version. These users causes data usage problem because in version 14 the code was problematic and caused high data usage problem.

如何使用规则在Firebase中阻止这些用户?

How can I block these users in firebase with rules?

现在是这样的:

{
  "rules": {
    ".read": true,
    ".write": true
  }
}

我想要这样的代码:

{
  "rules": {
    ".read": "if app version is greater than 14",
    ".write": "if app version is greater than 14"
  }
}

我可以使用规则吗?我能怎么做?如果没有,是否还有其他方法可以阻止使用低版本的用户.

Can I do this with rules? How can I do? If no, is there any other ways to block users who uses low versions.

推荐答案

无法将每个请求的此类信息传递给数据库.

There is no way to pass such information with each request to the database.

我能想到的最接近的事情是将其设置为用户的自定义声明,该声明已传递给数据库和安全规则.但是一个用户可能会在不同设备上使用该应用程序的不同版本,因此映射将无法正常工作.

The closest thing I can think of is setting it as a custom claim for the user, which is passed to the database and security rules. But a single user could be using different versions of the app on different devices, so that mapping won't work correctly.

最好的方法是在数据库中有一个具有最低客户端版本(或如果需要的话:数据模型的版本)的单个节点:

The best way would be to have a single node with the minimum client version (or if you want: the version of the data model) in the database:

minimumClientVersion: 15

然后在应用启动时,读取此编号,将其与应用版本进行对照,并告诉用户升级其应用不是最新的

Then when the app starts, read this number, check it against the app version, and tell the user to upgrade of their app is not up to date.

这篇关于如何在Firebase中按应用程序版本阻止用户的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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