统一的Firebase远程配置只获取默认值而不是真实值

时间:2018-01-30 12:43:37

标签: 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;
         }
     }
}

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

  

“获取数据......”,“获取成功完成!”

  

“远程数据已加载并准备就绪(上次提取时间为1/1/1970 12:00:00 AM)。”

但值为空。

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

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

ActivateFetched上的API声明它返回:

  

如果有Fetched Config,则为true,并且已激活。如果不是假的   找到了Fetched Config,或者已经激活了Fetched Config。

如何找到此问题的来源? (为什么没有找到提取的配置。它存在于项目控制台中:/)

1 个答案:

答案 0 :(得分:0)

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