ITPub博客

首页 > 移动开发 > ANDROID > Web | 快速集成华为AGC远程配置

Web | 快速集成华为AGC远程配置

原创 ANDROID 作者:华为开发者论坛 时间:2021-06-07 17:28:18 0 删除 编辑

最近发现华为AGC 远程配置服务开始支持Web 平台了,之前只支持Android 版本,期待Web 版本很久了,也迫不及待地集成体验了一下,集成的Demo 见 Github 。

集成步骤

1.   开通服务

a)    登录 AGC ,创建JS 应用

b)    开通远程配置

c)    点击“添加配置项”,新增远程配置的配置项

2.   集成SDK

a)   输入指令将npm 下载到项目中

npm install –save @agconnect/remoteconfig

3.   接入功能

a)   获取本地配置项

在vue 中创建本地配置map

应用本地配置

export function applyDefault(map) {
  return agconnect.remoteConfig().applyDefault(map);
}

b)    获取云端配置项

直接调用fetch 接口获取云端配置

export async function fetch() {
  return agconnect.remoteConfig().fetch().then(() => {
    return Promise.resolve();
  }).catch((err) => {
    return Promise.reject(err);
  });
}

c)   将配置应用到本地,分为实时应用到本地和生效上次配置两种。

   实时应用到本地:

直接调用apply 接口:

export function apply() {
  return agconnect
    .remoteConfig().apply().then((res) => {
        return Promise.resolve(res);
      }
    ).catch(error => {
      return Promise.reject(error);
    });
}

   生效上次获取的配置:

调用applyLastFetch 接口获取上次fetch 到的配置

//加载配置
export function applyLastLoad() {
  return agconnect
    .remoteConfig().loadLastFetched().then(async (res) => {
        if (res) {
          await agconnect.remoteConfig().apply(res);
        }
        return Promise.resolve(res);
      }
    ).catch(error => {
      return Promise.reject(error);
    });
}

d)   合并本地云端配置

直接调用getMergedAll 接口合并所有配置项

export function getMergedAll() {
  return agconnect.remoteConfig().getMergedAll();
}

e)    清除配置项

调用clearAll 接口清除配置项

export function clearAll() {
  agconnect.remoteConfig().clearAll();
}

f)    效果展示

点击获取,远端配置生效合并本地和云端的配置项,点击确定最终显示出所有的配置项。

 

想要了解更多相关内容,请参考:

在web 平台集成华为AGC 远程配置: https://github.com/AppGalleryConnect/agc-web-demos/tree/master/agc-romoteconfig-demo-javascript

Web 集成华为AGC 远程配置开发指南: https://developer.huawei.com/consumer/cn/doc/development/AppGallery-connect-Guides/agc-remoteconfig-web-getstarted-0000001056501223


原文链接: https://developer.huawei.com/consumer/cn/forum/topic/0202448065023410670?fid=0101271690375130218

原作者: Mayism

来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/69970551/viewspace-2775831/ ,如需转载,请注明出处,否则将追究法律责任。

请登录后发表评论 登录
全部评论

注册时间:2020-04-21

  • 博文量
    402
  • 访问量
    731013