4
votes

I'm trying to use the plugin cordova-plugin-firebase for retrieving Firebase Remote Configs, but value is always null.

Has anyone gotten this to work, or see something wrong in my implementation?

Thanks.

$ionicPlatform.ready(function () {
   if (window.FirebasePlugin) {
      window.FirebasePlugin.getValue("xxx", function (value) {
         console.log(value);
      }, function (error) {
         console.error(error);
      });
   }
});

Environment

Cordova CLI: 7.0.1 Gulp version: CLI version 1.2.1 Gulp local: Local version 3.9.1 Ionic Framework Version: 1.3.2 Ionic CLI Version: 2.1.1 Ionic App Lib Version: 2.1.1 ios-deploy version: 1.9.1 ios-sim version: 5.0.6 OS: Mac OS X Sierra Node Version: v4.4.0 Xcode version: Xcode 8.3.1 Build version 8E1000a

1

1 Answers

5
votes

Before you could use getValue, you need to fetch and activate the remote config.

Like this:

$ionicPlatform.ready(() => {
if (window.FirebasePlugin) {
  window.FirebasePlugin.fetch(600,(returnValue) => {
    window.FirebasePlugin.activateFetched((isActivated) => {
      //Check if the fetched remote config is activated
      if (isActivated) {
        window.FirebasePlugin.getValue("xxx", (value) => {
          console.log(value);
        }, (error) => {
          console.error(error);
        });
      }
    });
  });
}

});

Do you know you could use (currently beta) Ionic Firebase plugin to make your life easier with these firebase functions?

Edit: I've added the following clarifying image to add some more context on why you need to first fetch the remote config and then activate it. More documentation can be found on the firebase site, enter image description here

Hope this helps...