private void fetchComplete(Task fetchTask) { if (fetchTask.IsCanceled) { Debug.Log("fetch cancelled"); } else if (fetchTask.IsFaulted) { Debug.Log("fetch encontered an error."); } else if (fetchTask.IsCompleted) { Debug.Log("Fetch completed successfully!"); } var info = FirebaseRemoteConfig.Info; switch (info.LastFetchStatus) { case LastFetchStatus.Success: FirebaseRemoteConfig.ActivateFetched(); break; case LastFetchStatus.Failure: break; case LastFetchStatus.Pending: break; default: throw new ArgumentOutOfRangeException(); } setValues(); loadReward(); }
/** * Fetch discount from server. */ private async System.Threading.Tasks.Task FetchDiscount() { mPriceTextView.SetText(LOADING_PHRASE_CONFIG_KEY, null); long cacheExpiration = 3600; // 1 hour in seconds. // If in developer mode cacheExpiration is set to 0 so each fetch will retrieve values from // the server. if (mFirebaseRemoteConfig.Info.ConfigSettings.IsDeveloperModeEnabled) { cacheExpiration = 0; } try { await mFirebaseRemoteConfig.FetchAsync(cacheExpiration); Toast.MakeText(this, "Fetch Succeeded", ToastLength.Long).Show(); // Once the config is successfully fetched it must be activated before newly fetched // values are returned. mFirebaseRemoteConfig.ActivateFetched(); } catch { Toast.MakeText(this, "Fetch Failed", ToastLength.Long).Show(); } DisplayPrice(); }
private void Awake() { manager = GetComponent <UIManager>(); FirebaseApp.CheckAndFixDependenciesAsync().ContinueWithOnMainThread <DependencyStatus>((task) => { DependencyStatus status = task.Result; if (status == DependencyStatus.Available) { App = FirebaseApp.DefaultInstance; Auth = FirebaseAuth.DefaultInstance; functions = FirebaseFunctions.DefaultInstance; functionReference = functions.GetHttpsCallable("RequestMessage"); manager.TurnOff(manager.AuthBlocker); manager.TurnOff(manager.AnalyticsBlocker); App.SetEditorDatabaseUrl("https://fir-n-ix.firebaseio.com/"); dbReference = FirebaseDatabase.DefaultInstance.RootReference; FirebaseMessaging.TokenReceived += OnTokenReceived; FirebaseMessaging.MessageReceived += OnMessageReceived; FirebaseMessaging.TokenRegistrationOnInitEnabled = true; defaults.Add("RemoteTest", 25); FirebaseRemoteConfig.SetDefaults(defaults); FirebaseRemoteConfig.FetchAsync(TimeSpan.Zero).ContinueWithOnMainThread((remoteConfigTask) => { FirebaseRemoteConfig.ActivateFetched(); RemoteConfigResult = FirebaseRemoteConfig.GetValue("RemoteTest").StringValue; manager.TurnOff(manager.RemoteConfigBlocker); }); storage = FirebaseStorage.DefaultInstance; } else { Debug.Log(string.Format("Can't resolve all Firebase dependencies: {0}", status)); } }); }
// This needs to be called when a value is expected to be different or the GetValue(..) values will be cached public static void FlushCache() { #if remote_config FirebaseRemoteConfig.ActivateFetched(); staticRef.RemoteConfigReady(); #endif }
static void FetchData() { if (FirebaseManager.FirebaseReady) { FetchDataAsync((task) => { Debug.Log("Fetch async done"); FirebaseRemoteConfig.ActivateFetched(); onFetchComplete?.Invoke(null, true); }); } }
private 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(); OnRemoteConfigFetched(); #if VIPERA_CORE MainThreadQueue.Enqueue(SetLastSuccessedFetchDate); #else SetLastSuccessedFetchDate(); #endif break; case LastFetchStatus.Failure: #if DEVELOPMENT_BUILD || UNITY_EDITOR switch (info.LastFetchFailureReason) { case FetchFailureReason.Error: Debug.Log("Fetch failed: " + fetchTask.Exception.ToString()); break; case FetchFailureReason.Throttled: Debug.Log("Fetch throttled until " + info.ThrottledEndTime); break; } #endif break; case LastFetchStatus.Pending: #if DEVELOPMENT_BUILD || UNITY_EDITOR Debug.Log("Latest Fetch call still pending."); #endif break; } isFetchInProgress = false; }
private void GetRemoteConfig() { try { firebaseRemoteConfig.Fetch(0); firebaseRemoteConfig.ActivateFetched(); data = firebaseRemoteConfig.GetString(DEFAULT_THEME); } catch (Exception e) { Console.WriteLine("ERROR REMOTE CONFIG: " + e.Message); } }
// ref: https://stackoverflow.com/questions/48521807/firebase-remote-config-in-unity-get-only-default-values-and-not-real-ones private static void RemoteSettingsFetch(Task fetchTask) { if (fetchTask.IsCanceled) { Debug.Log("Remote Settings: Fetch canceled."); } else if (fetchTask.IsFaulted) { Debug.Log("Remote Settings: Fetch encountered an error."); } else if (fetchTask.IsCompleted) { Debug.Log("Remote Settings: Fetch completed!"); var info = FirebaseRemoteConfig.Info; switch (info.LastFetchStatus) { case LastFetchStatus.Success: Debug.Log(string.Format("Remote Settings: Data loaded and ready (last fetch time {0}).", info.FetchTime)); if (FirebaseRemoteConfig.ActivateFetched()) { rsActivateFetched = true; SGDebug.Log(string.Format("Remote Settings: Activate Fetched and Data loaded and ready (last fetch time {0}).", info.FetchTime)); } break; case LastFetchStatus.Failure: switch (info.LastFetchFailureReason) { case FetchFailureReason.Error: Debug.LogError("Remote Settings: Fetch failed for unknown reason"); break; case FetchFailureReason.Throttled: Debug.LogError("Remote Settings: Fetch throttled until " + info.ThrottledEndTime); break; } break; case LastFetchStatus.Pending: Debug.LogWarning("Remote Settings: Latest Fetch call still pending."); break; default: Debug.LogWarning(string.Format("Remote Settings: Something get wrong. Data: {0}", info)); break; } } }
private void FetchComplete(Task fetchTask) { if (fetchTask.IsCanceled) { this.Log("[FIREBASE] Own interstitial data fetch canceled.", LogLevel.FrameworkErrorInfo); } else if (fetchTask.IsFaulted) { this.Log("[FIREBASE] Own interstitial data fetch encountered an error.", LogLevel.FrameworkErrorInfo); } else if (fetchTask.IsCompleted) { this.Log("[FIREBASE] Own interstitial data fetch completed successfully!", LogLevel.FrameworkInfo); } var info = FirebaseRemoteConfig.Info; switch (info.LastFetchStatus) { case LastFetchStatus.Success: FirebaseRemoteConfig.ActivateFetched(); this.Log($"[FIREBASE] Own interstitial data loaded and ready (last fetch time {info.FetchTime}).", LogLevel.FrameworkInfo); LogEvent("own_interstitial_load_status", "status", "success"); ownInterstitial.PrepareInterstitialData(); break; case LastFetchStatus.Failure: LogEvent("own_interstitial_load_status", "status", "failure"); ownInterstitial.OnFirebaseInitializationFailed(); switch (info.LastFetchFailureReason) { case FetchFailureReason.Error: this.Log("[FIREBASE] Own interstitial data fetch failed for unknown reason.", LogLevel.FrameworkErrorInfo); break; case FetchFailureReason.Throttled: this.Log("[FIREBASE] Own interstitial data fetch throttled until " + info.ThrottledEndTime, LogLevel.FrameworkErrorInfo); break; } break; case LastFetchStatus.Pending: this.Log("[FIREBASE] Latest own interstitial data fetch call still pending.", LogLevel.FrameworkInfo); break; } }
public string GetRemoteDataString(string key) { try { InitRemoteConfig(); firebaseRemoteConfig.Fetch(0); firebaseRemoteConfig.ActivateFetched(); return(firebaseRemoteConfig.GetString(key)); } catch (Exception) { return(Resource.Xml.remote_config_defaults.ToString()); } }
private static List <KeyValuePair <string, string> > ParseConfigsFromFirebase() { FirebaseRemoteConfig.ActivateFetched(); IEnumerable <string> keys = FirebaseRemoteConfig.Keys; string[] array = (from key in keys where FirebaseRemoteConfig.GetValue(key).StringValue != string.Empty select key).ToArray(); m_crc32 = GetCRC(array); List <JSONObject> messages = (from key in array select FirebaseRemoteConfig.GetValue(key).StringValue into raw select JSONObject.Create(raw)).ToList(); return(GetConfigs(messages).Concat(GetGameSettings(messages)).ToList()); }
private static async UniTask OnRemote(TimeSpan cache) { try { await FirebaseRemoteConfig.FetchAsync(cache); FirebaseRemoteConfig.ActivateFetched(); await UniTask.SwitchToMainThread(); StencilRemote.NotifyRemoteConfig(); } catch (Exception e) { Debug.LogError($"Firebase Remote Config failed. {e.InnerException?.Message}"); } }
private static void FetchComplete(Task fetchTask) { if (fetchTask.IsCanceled) { Debug.LogWarning("FazApp: Own interstitial data fetch canceled."); } else if (fetchTask.IsFaulted) { Debug.LogError("FazApp: Own interstitial data fetch encountered an error."); } else if (fetchTask.IsCompleted) { Debug.Log("FazApp: Own interstitial data fetch completed successfully!"); } var info = FirebaseRemoteConfig.Info; switch (info.LastFetchStatus) { case LastFetchStatus.Success: FirebaseRemoteConfig.ActivateFetched(); Debug.Log($"FazApp: Own interstitial data loaded and ready (last fetch time {info.FetchTime})."); OwnIntertitialDataIsReady = true; break; case LastFetchStatus.Failure: OwnInterstitalDataFetchFailed = true; switch (info.LastFetchFailureReason) { case FetchFailureReason.Error: Debug.LogError("FazApp: Own interstitial data fetch failed for unknown reason"); break; case FetchFailureReason.Throttled: Debug.LogWarning("FazApp: Own interstitial data fetch throttled until " + info.ThrottledEndTime); break; } break; case LastFetchStatus.Pending: Debug.Log("FazApp: Latest own interstitial data fetch call still pending."); break; } }
/// <summary> /// Calls FetchAsync and ActivateFetched on FirebaseRemoteConfig, initializing its values and /// triggering provided callbacks once. /// </summary> /// <param name="callback">Callback to schedule after RemoteConfig is initialized.</param> /// <param name="forceRefresh">If true, force refresh of RemoteConfig params.</param> public static void RemoteConfigActivateFetched(Action callback, bool forceRefresh = false) { lock (activateFetchCallbacks) { if (activateFetched && !forceRefresh) { callback(); return; } else { activateFetchCallbacks.Add(callback); } if (!fetching) { #if UNITY_EDITOR var settings = FirebaseRemoteConfig.Settings; settings.IsDeveloperMode = true; FirebaseRemoteConfig.Settings = settings; #endif // Get the default values from the current SyncTargets. var syncObjects = Resources.FindObjectsOfTypeAll <RemoteConfigSyncBehaviour>(); var syncTargets = SyncTargetManager.FindTargets(syncObjects).GetFlattenedTargets(); var defaultValues = new Dictionary <string, object>(); foreach (var target in syncTargets.Values) { defaultValues[target.FullKeyString] = target.Value; } Initialize(status => { FirebaseRemoteConfig.SetDefaults(defaultValues); FirebaseRemoteConfig.FetchAsync(TimeSpan.Zero).ContinueWith(task => { lock (activateFetchCallbacks) { fetching = false; activateFetched = true; var newlyActivated = FirebaseRemoteConfig.ActivateFetched(); CallActivateFetchedCallbacks(); } }); }); } } }
public void Init() { _firebaseRemoteConfig = FirebaseRemoteConfig.Instance; #if DEBUG var configSettings = new FirebaseRemoteConfigSettings.Builder().SetDeveloperModeEnabled(true).Build(); _firebaseRemoteConfig.SetConfigSettings(configSettings); long cacheExpiration = 0; #else var configSettings = new FirebaseRemoteConfigSettings.Builder().SetDeveloperModeEnabled(false).Build(); _firebaseRemoteConfig.SetConfigSettings(configSettings); long cacheExpiration = 3600; // 1 hour in seconds. #endif _firebaseRemoteConfig.SetDefaults(Resource.Xml.firebase_default_settings); Task.Factory.StartNew(async() => { await _firebaseRemoteConfig.FetchAsync(cacheExpiration); _firebaseRemoteConfig.ActivateFetched(); }); }
private static void FetchDataAsync() { Task task2 = FirebaseRemoteConfig.FetchAsync(TimeSpan.Zero); task2.ContinueWith(delegate { ConfigInfo info = FirebaseRemoteConfig.Info; switch (info.LastFetchStatus) { case LastFetchStatus.Success: FirebaseRemoteConfig.ActivateFetched(); UnityEngine.Debug.Log("Fetch is completed."); break; case LastFetchStatus.Failure: switch (info.LastFetchFailureReason) { } break; } }); }
private static void PerformRemoteSettingsFetch(Task fetchTask) { Debug.Log("<color=#ffa500ff>Remote Config</color> - Request fetch"); fetchTask .ContinueWith(task => { if (!task.IsCompleted) { Debug.LogError("<color=#ffa500ff>Remote Config</color> - Fetch task cancelled or failed"); return; } var info = FirebaseRemoteConfig.Info; if (info.LastFetchStatus != LastFetchStatus.Success) { Debug.LogError("<color=#ffa500ff>Remote Config</color> - Fetch failed or is still pending"); return; } Debug.Log("<color=#ffa500ff>Remote Config</color> - Fetched"); FirebaseRemoteConfig.ActivateFetched(); Debug.Log("<color=#ffa500ff>Remote Config</color> - Fetched activated"); }) .ContinueWith(task => { if (!task.IsCompleted) { Debug.LogError("<color=#ffa500ff>Remote Config</color> - Fetch task cancelled or failed"); return; } VariablesUpdatedHandler.VariablesUpdated(); Debug.Log("<color=#ffa500ff>Remote Config</color> - Variables updated"); _remoteConfigFetched = true; _remoteConfigFetch.Dispose(); }, TaskScheduler.FromCurrentSynchronizationContext()); }
void FetchData() { try { if (FetchExist()) { FirebaseRemoteConfig.ActivateFetched(); OnRemoteConfigFetched(); OnFetchComplete?.Invoke(); } DateTime lastFetch = GetLastSuccessedFetchDate(); TimeSpan timeSinceLastFetch = DateTime.Now - lastFetch; if (timeSinceLastFetch.TotalSeconds > GetCacheExpiration().TotalSeconds) { StartFetchData(); } } catch (Exception ex) { Debug.LogError(ex); } }
public async Task <bool> Fetch() { await _firebaseRemote.FetchAsync(CacheTimeout); return(_firebaseRemote.ActivateFetched()); }