【发布时间】:2018-07-09 08:40:24
【问题描述】:
我正在尝试将 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 已激活。
我怎样才能找到这个问题的根源? (为什么没有找到获取的配置。它存在于项目控制台中:/)
【问题讨论】:
-
您确定点击了 Firebase 控制台中的“发布”按钮以公开这些值吗?
-
我没有看到发布按钮 :(
标签: c# firebase unity3d unity5 firebase-remote-config