gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-03 14:57:32 24 4
gpt4 key购买 nike

我正在尝试将 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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com