Skip to content

Instantly share code, notes, and snippets.

@gmYusuf
Created April 30, 2021 05:50
Show Gist options
  • Save gmYusuf/9f029a435531d5ae8c144fd73aa8c796 to your computer and use it in GitHub Desktop.
Save gmYusuf/9f029a435531d5ae8c144fd73aa8c796 to your computer and use it in GitHub Desktop.
RemoteConfigDemo
using HuaweiMobileServices.RemoteConfig;
using HuaweiMobileServices.Utils;
using System;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class RemoteConfigDemo : MonoBehaviour
{
private Text countOfVariables;
string TAG = "RemoteConfig Demo";
void Start()
{
countOfVariables = GameObject.Find("countOfVariables").GetComponent<Text>();
}
public void Fetch()
{
HMSRemoteConfigManager.Instance.OnFecthSuccess = OnFecthSuccess;
HMSRemoteConfigManager.Instance.OnFecthFailure = OnFecthFailure;
HMSRemoteConfigManager.Instance.Fetch();
}
private void OnFecthSuccess(ConfigValues config)
{
HMSRemoteConfigManager.Instance.Apply(config);
Debug.Log($"[{TAG}]: fetch() Success");
}
private void OnFecthFailure(HMSException exception)
{
Debug.Log($"[{TAG}]: fetch() Failed Error Code => {exception.ErrorCode} Message => {exception.WrappedExceptionMessage}");
}
public void GetMergedAll()
{
Dictionary<string, object> dictionary = HMSRemoteConfigManager.Instance.GetMergedAll();
countOfVariables.text = $"Count of Variables : {dictionary.Count}";
}
public void ClearAll()
{
HMSRemoteConfigManager.Instance.ClearAll();
GetMergedAll();
}
public void ApplyDefault()
{
Dictionary<string, object> dictionary = new Dictionary<string, object>();
dictionary.Add("shape",2);
dictionary.Add("color", "green ");
dictionary.Add("style", 5);
HMSRemoteConfigManager.Instance.ApplyDefault(dictionary);
GetMergedAll();
}
public void ApplyDefaultXml()
{
HMSRemoteConfigManager.Instance.ApplyDefault("xml/remoteConfig");
GetMergedAll();
}
public void LoadLastFetched()
{
Debug.Log($"[{TAG}]: LoadLastFetched {HMSRemoteConfigManager.Instance.LoadLastFetched().getValueAsString("abc")}");
}
public void DeveloperMode(bool val)
{
HMSRemoteConfigManager.Instance.SetDeveloperMode(val);
}
public void GetSource()
{
Debug.Log($"[{TAG}]: GetSource(Key) {HMSRemoteConfigManager.Instance.GetSource("Key")}");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment