c# - 统一的 Firebase 远程配置仅获取默认值而不是真实值

标签 c# firebase unity3d unity5 firebase-remote-config

我正在尝试将 Firebase 远程配置实现到统一项目中。

这是唯一正在运行的脚本:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Firebase;
using Firebase.RemoteConfig;
using System;
using System.Threading.Tasks;

public class FirebaseAlt : MonoBehaviour
{
    private  DependencyStatus dependencyStatus = DependencyStatus.UnavailableOther;

    void Awake()
    {
        FirebaseApp.CheckAndFixDependenciesAsync().ContinueWith(task => {
            dependencyStatus = task.Result;
            if (dependencyStatus == DependencyStatus.Available)
            {
                 InitializeFirebase();
            }
            else
            {
                 Debug.LogError("Could not resolve all Firebase dependencies: " + dependencyStatus);
            }
         });
     }

     // Initialize remote config, and set the default values.
     void InitializeFirebase()
     {
          FetchData();
     }

     // Start a fetch request.
     public void FetchData()
     {
          Debug.Log("Fetching data...");
          // FetchAsync only fetches new data if the current data is older than the provided
          // timespan.  Otherwise it assumes the data is "recent enough", and does nothing.
          // By default the timespan is 12 hours, and for production apps, this is a good
          // number.  For this example though, it's set to a timespan of zero, so that
          // changes in the console will always show up immediately.
          Task fetchTask = FirebaseRemoteConfig.FetchAsync(TimeSpan.Zero);
          fetchTask.ContinueWith(FetchComplete);
      }

      void FetchComplete(Task fetchTask)
      {
           if (fetchTask.IsCanceled)
           {
               Debug.Log("Fetch canceled.");
           }
           else if (fetchTask.IsFaulted)
           {
               Debug.Log("Fetch encountered an error.");
           }
           else if (fetchTask.IsCompleted)
           {
               Debug.Log("Fetch completed successfully!");
           }

           var info = FirebaseRemoteConfig.Info;

           switch (info.LastFetchStatus)
           {
               case LastFetchStatus.Success:
                   FirebaseRemoteConfig.ActivateFetched();

                   Debug.Log(string.Format("Remote data loaded and ready (last fetch time {0}).", info.FetchTime));
                   string stop = FirebaseRemoteConfig.GetValue("stops").StringValue;
                   Debug.Log("Value: " + (string.IsNullOrEmpty(stop) ? "NA" : stop));

                   // Also tried this way, but then it doesn't enter the IF block
                   /*if (FirebaseRemoteConfig.ActivateFetched())
                   { 
                        Debug.Log(string.Format("Remote data loaded and ready (last fetch time {0}).", info.FetchTime));

                        string stop = FirebaseRemoteConfig.GetValue("stops").StringValue;
                        Debug.Log("Value: " + (string.IsNullOrEmpty(stop) ? "NA" : stop));
                   }*/
                   break;
               case LastFetchStatus.Failure:
                   switch (info.LastFetchFailureReason)
                   {
                       case FetchFailureReason.Error:
                             Debug.Log("Fetch failed for unknown reason");
                             break;
                       case FetchFailureReason.Throttled:
                             Debug.Log("Fetch throttled until " + info.ThrottledEndTime);
                             break;
                   }
                  break;
               case LastFetchStatus.Pending:
                  Debug.Log("Latest Fetch call still pending.");
                  break;
         }
     }
}

当我运行此代码时,我得到了所有正确的响应

"Fetching data...", "Fetch completed successfully!"





"Remote data loaded and ready (last fetch time 1/1/1970 12:00:00 AM)."



但值为空。

如果我查看键是什么,我会得到一个默认值列表(我在测试开始时放置了它,但删除了它),但没有我放入 firebase 控制台的任何新键(如 stops 键我试图展示)。

我尝试了几乎所有我能找到的解决方案,但无济于事。我有 google-services.json (不知道是否与此相关),NDK 版本 r13b 。将 FirebaseRemoteConfig.Settings.IsDeveloperMode 更改为 true。我还尝试在 ActivateFetched() 之后等待一段时间(1 分钟),看看它是否有任何改变。

ActivateFetched 上的 API 声明它返回:

true if there was a Fetched Config, and it was activated. false if no Fetched Config was found, or the Fetched Config was already activated.



我怎样才能找到这个问题的根源? (为什么没有找到获取的配置。它存在于项目控制台中:/)

最佳答案

由于对远程配置服务器的请求过多,您的 Ip 似乎被标记为受限。只需要再等一天,一切都应该工作或更换计算机。这是一个博客,其中列出了使用远程配置时最常见的错误以及如何预防。希望它会有所帮助。
https://killertee.wordpress.com/2020/01/08/make-use-of-firebase-remote-config-in-your-unity-game/

关于c# - 统一的 Firebase 远程配置仅获取默认值而不是真实值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48521807/

相关文章:

c# - 是否已知代码优先 EF 无法与包含大量 DbSet 的 DbContext 一起使用?

c# - 在 .NET 应用程序中传递 XML 的最佳方式是什么?

c# - 在 C# webBrowser 控件中调用 Javascript 函数

android - Firebase Remote Config 长请求响应时间问题

c# - 更新到 Unity 2019.3 后无法编译 Unity WebGL

c# - 自定义随机数生成器

c# - 为什么 Azure Function 应用程序中使用的 Microsoft.Azure.WebJobs.HttpTriggerAttribute 是参数属性而不是方法属性?

java - 如何访问另一个 firebase 项目的数据

ios - firebase objective c 查询

c# - 如何统一在纹理上绘制圆圈?