Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Firebase remote config - Can not get key list from default value dictionary #62

Closed
takaaptech opened this issue Feb 28, 2017 · 5 comments
Assignees

Comments

@takaaptech
Copy link

I try to get key, value list from defaults dictionary, in editor mode it works. But on real device (android device). It print nothing from for each loop.
Example MonoBehaviour as bellow:

using System;
using System.Threading.Tasks;
using Firebase.RemoteConfig;
using OneSoftGame.Tools;
using System.Diagnostics;
using System.Collections;
using UnityEngine;

public class RMManager : MonoBehaviour
{

    Firebase.DependencyStatus dependencyStatus = Firebase.DependencyStatus.UnavailableOther;

    /// <summary>
    /// Awake is called when the script instance is being loaded.
    /// </summary>
    void Start()
    {
        dependencyStatus = Firebase.FirebaseApp.CheckDependencies();
        if (dependencyStatus != Firebase.DependencyStatus.Available)
        {
            Firebase.FirebaseApp.FixDependenciesAsync().ContinueWith(task =>
            {
                dependencyStatus = Firebase.FirebaseApp.CheckDependencies();
                if (dependencyStatus == Firebase.DependencyStatus.Available)
                {
                    print("RemoteConfig configured and ready!");
					InitFB();
                }
                else
                {
                    print(
                        "Could not resolve all Firebase dependencies: "   dependencyStatus);
                }
            });
        }
        else
        {
            print("RemoteConfig configured and ready!");
			InitFB();
        }
    }

    void InitFB()
    {
        print("Start InitFB");
		ListDefaultValues();
        //Test("key1");
        //Test("key2");
        SetDefaultValues("key1", "value1");
        //Test("key1");
        //Test("key2");
        ListDefaultValues();
        SetDefaultValues("key2", "value2");
        //Test("key1");
        //Test("key2");
        ListDefaultValues();

    }
    void Test(string key)
    {
           print("Start Test key:"  key);
           var item = Firebase.RemoteConfig.FirebaseRemoteConfig.GetValue(key);
            DebugFirebaseConfigValue(item);
    }

    void SetDefaultValues(string key, object value)
    {
        print("Start SetDefaultValues for key:"  key);
        System.Collections.Generic.Dictionary<string, object> defaults =
            new System.Collections.Generic.Dictionary<string, object>();
        defaults.Add(key, value);
        Firebase.RemoteConfig.FirebaseRemoteConfig.SetDefaults(defaults);
        ListDefaultValues();
    }

    private void ListDefaultValues()
    {
        print("Start ListDefaultValues GetKeysByPrefix     ");
        var keys = Firebase.RemoteConfig.FirebaseRemoteConfig.GetKeysByPrefix("","");


        foreach (var key in keys)
        {
            print("ListDefaultValues:"   key);
            var item = Firebase.RemoteConfig.FirebaseRemoteConfig.GetValue(key);
            DebugFirebaseConfigValue(item);
        }
        print("Start ListDefaultValues GetKeys     ");
        keys = Firebase.RemoteConfig.FirebaseRemoteConfig.GetKeys("");
        
        foreach (var key in keys)
        {
            print("ListDefaultValues:"   key);
            var item = Firebase.RemoteConfig.FirebaseRemoteConfig.GetValue(key);
            DebugFirebaseConfigValue(item);
        }

        print("Start ListDefaultValues .Keys     ");
        keys = Firebase.RemoteConfig.FirebaseRemoteConfig.Keys;
        
        foreach (var key in keys)
        {
            print("ListDefaultValues:"   key);
            var item = Firebase.RemoteConfig.FirebaseRemoteConfig.GetValue(key);
            DebugFirebaseConfigValue(item);
        }


        print("End ListDefaultValues     ");
    }

    public void DebugFirebaseConfigValue(ConfigValue item)
    {
        try
        {
            print("Debug ConfigValue Start -----------------");
            print("Source:"   item.Source);
            print("StringValue:"   item.StringValue);
            print("Debug ConfigValue End -----------------");
        }
        catch (Exception ex)
        {
            print("DebugFirebaseConfigValue Exception:"   ex.Message);
        }

    }
}
@takaaptech
Copy link
Author

I just build TestApp from this repo in to android devices, and when press Display All Keys, this is list only key have on server (Not defaults key set from client)

@a-maurice
Copy link
Contributor

Sorry for the delay in response. Unfortunately, that's an underlying bug, where it is only looking at server keys, and it may be a bit before we can get a fix in.

In the meantime, if you need to be able to get the keys from SetDefaults, I'd recommend preserving them yourself in a List when you perform the call to SetDefaults. If you need more details on exactly how that might work, let me know.

Hopefully that helps, and thanks for finding this issue!

@frankkienl
Copy link

For people using Remote Config, but with the Unity:
https://stackoverflow.com/a/44588535/1398449

(There is no bug-tracker for "normal Android" Firebase sdk)

@stewartmiles
Copy link
Contributor

We have this fix linked up for the next minor release, 4.1.x. We'll post an update when it's ready.

@stewartmiles
Copy link
Contributor

This issue is now resolved in the 4.1.0 release of the Firebase Unity SDK. For more information, see
https://firebase.google.com/support/release-notes/unity#4.1.0

Cheers,
Stewart

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

4 participants