首页 文章

如何使用Cordova检索Firebase“远程配置”

提问于
浏览
4

我正在尝试使用插件cordova-plugin-firebase来检索Firebase远程配置,但 value 始终是 null .

有没有人让这个工作,或在我的实现中看到错误?

谢谢 .

$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版本:CLI版本1.2.1 Gulp本地:本地版本3.9.1 Ionic Framework版本:1.3.2 Ionic CLI版本:2.1.1 Ionic App Lib版本:2.1.1 ios-deploy版本: 1.9.1 ios-sim版本:5.0.6操作系统:Mac OS X Sierra节点版本:v4.4.0 Xcode版本:Xcode 8.3.1构建版本8E1000a

1 回答

  • 5

    在使用getValue之前,您需要获取并激活远程配置 .

    像这样:

    $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);
            });
          }
        });
      });
    }
    

    });

    你知道你可以使用(目前为测试版)Ionic Firebase plugin使用这些firebase功能让你的生活更轻松吗?

    编辑:我添加了以下澄清图像,以添加更多上下文,说明为什么需要首先获取远程配置然后激活它 . 更多文档可以found on the firebase site
    enter image description here

    希望这可以帮助...

相关问题