如何解决如何统一检查 Firebase 远程配置超时?
你好所以我想在unity上检查这个java函数
FirebaseRemoteConfigSettings configSettings = new FirebaseRemoteConfigSettings.Builder()
.setMinimumFetchIntervalInSeconds(MINIMUM_FETCH_INTERVAL)
.setFetchTimeoutInSeconds(FETCH_TIME_OUT)
.build();
但是unity上好像没有config setting interval
也不明白firebase文档上说的是什么
这里是我关于 unity 的 firebse 脚本
public static _FirebaseRemoteConfig instance;
private void Awake()
{
if (instance != null)
{
Destroy(gameObject);
}
else
{
DontDestroyOnLoad(gameObject);
instance = this;
}
InitializeFirebase();
}
public int countingUpdate;
public int maxCount;
Firebase.DependencyStatus dependencyStatus = Firebase.DependencyStatus.UnavailableOther;
// Use this for initialization
void Start()
{
}
public void InitializeFirebase()
{
System.Collections.Generic.Dictionary<string,object> defaults =
new System.Collections.Generic.Dictionary<string,object>();
defaults.Add("config_test_string","default local string");
defaults.Add("config_test_int",1);
defaults.Add("config_test_float",1.0);
defaults.Add("config_test_bool",false);
Firebase.RemoteConfig.FirebaseRemoteConfig.SetDefaults(defaults);
Debug.Log("Remote config ready!");
FetchFireBase();
}
public void FetchFireBase()
{
FetchDataAsync();
}
public void ShowData()
{
Debug.Log("maxCountToShowAdmob: " +
Firebase.RemoteConfig.FirebaseRemoteConfig.GetValue("MaxCountShowIntersitialAds").StringValue);
}
// Start a fetch request.
public Task FetchDataAsync()
{
Debug.Log("Fetching data...");
System.Threading.Tasks.Task fetchTask = Firebase.RemoteConfig.FirebaseRemoteConfig.FetchAsync(
TimeSpan.Zero);
return 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 = Firebase.RemoteConfig.FirebaseRemoteConfig.Info;
switch (info.LastFetchStatus)
{
case Firebase.RemoteConfig.LastFetchStatus.Success:
Firebase.RemoteConfig.FirebaseRemoteConfig.ActivateFetched();
Debug.Log(String.Format("Remote data loaded and ready (last fetch time {0}).",info.FetchTime));
break;
case Firebase.RemoteConfig.LastFetchStatus.Failure:
switch (info.LastFetchFailureReason)
{
case Firebase.RemoteConfig.FetchFailureReason.Error:
Debug.Log("Fetch failed for unknown reason");
break;
case Firebase.RemoteConfig.FetchFailureReason.Throttled:
Debug.Log("Fetch throttled until " + info.ThrottledEndTime);
break;
}
break;
case Firebase.RemoteConfig.LastFetchStatus.Pending:
Debug.Log("Latest Fetch call still pending.");
break;
}
}
public void DisplayAds()
{
countingUpdate++;
if (countingUpdate % int.Parse(Firebase.RemoteConfig.FirebaseRemoteConfig.GetValue("MaxCountShowIntersitialAds").StringValue) == 0)
{
//ADs ready to show
_AdmobAds.instance.ShowInterstitialAd();
countingUpdate = 0;
}
}
解决方法
7.1.0 Unity SDK 对远程配置的工作方式进行了一些更改,因此文档现在可能有点混乱。
使用 7.1.0 SDK,以下代码应该可以工作:
var configSettings = new Firebase.RemoteConfig.ConfigSettings()
{
MinimumFetchInternalInMilliseconds = 42
};
FirebaseRemoteConfig.DefaultInstance.SetConfigSettingsAsync(configSettings).ContinueWithOnMainThread(task =>
{
if (task.IsCompleted && task.Exception != null)
{
// do remote config stuff
}
});
但如果您打算使用 FetchAsync(TimeSpan.Zero)
,我认为您不会发现更改默认的最小获取间隔会有任何作用。
我还会警告您,看起来您是安全的(只需执行 Debug.Log
),但是如果您想对 Unity 对象执行任何操作(通常使用 UnityEngine
命名空间),您可能想改变:
return fetchTask.ContinueWith(FetchComplete);
到
return fetchTask.ContinueWithOnMainThread(FetchComplete);
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。