Firebase远程配置-初始访存返回本地默认值 [英] Firebase Remote Config - Initial fetch return local default values

查看:78
本文介绍了Firebase远程配置-初始访存返回本地默认值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Firebase Remote Config来获取远程数据,而我的应用需要从第一次启动开始就获取最新数据.

I'm using Firebase Remote Config to fetch remote data and my app needs an up-to-date data from the first launch.

我正在获取并更新应用程序的 onCreate():

I'm doing a fetch and update in my Application's onCreate():

mFirebaseRemoteConfig.fetch(cacheExpiration)
    .addOnCompleteListener(new OnCompleteListener<Void>() {
        @Override
        public void onComplete(@NonNull Task<Void> task) {
            if (task.isSuccessful()) {
                mFirebaseRemoteConfig.activateFetched();
            }
        }
    });

并使用:

myValue = mFirebaseRemoteConfig.getBoolean(Constants.FIREBASE_REMOTE_MY_VALUE);

  1. 第一次获取工作良好(成功触发了 activateFetched()),但它返回了 remote_config_defaults 值,而不是已发布的远程配置.
  2. 第二次获取(即使几秒钟后)也会返回远程值.
  3. 此后,以下提取受cacheExpiration规则的约束(完全可以).
  1. The first fetch works well (activateFetched() is successfully triggered), but it returns the remote_config_defaults value and not the published remote config.
  2. The second fetch, even a few seconds later, returns the remote value.
  3. After that, the following fetches are subject to the cacheExpiration rule (which is totally OK).

您知道为什么在第一次调用时未获取我的远程值吗?

Any idea why my remote value is not fetched at the first call?

推荐答案

听起来好像您正在忽略获取远程参数的异步特性.发送到Firebase服务器的请求并收到答复后,将触发 onComplete()回调.这将花费一秒钟的时间,甚至更多.

It sounds like you are overlooking the asynchronous nature of fetching the remote parameters. The onComplete() callback fires after a request to the Firebase servers is sent and the reply received. This will take a fraction of a second, maybe more.

如果您的语句使用获取的值:

If your statement to use the fetched value:

myValue = mFirebaseRemoteConfig.getBoolean(Constants.FIREBASE_REMOTE_MY_VALUE);

跟随 fetch()的调用,并且不在 onComplete()回调中,它将在配置数据被获取之前执行已收到.第二个呼叫似乎起作用,因为已经有足够的时间使第一个呼叫完成,并且存在它已提取和激活的数据.

follows the call to fetch() and is not in the onComplete() callback, it will execute before the config data has been received. The second call only appears to work because enough time has elapsed for the first call to complete and the data it fetched and activated is present.

这篇关于Firebase远程配置-初始访存返回本地默认值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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