最近发现华为AGC近程配置服务开始反对Web平台了,之前只反对Android版本,期待Web版本很久了,也急不可待地集成体验了一下,集成的Demo见Github。
集成步骤
- 开明服务
a) 登录AGC,创立JS利用
b) 开明近程配置
c) 点击“增加配置项”,新增近程配置的配置项
- 集成SDK
a) 输出指令将npm下载到我的项目中
npm install –save @agconnect/remoteconfig
- 接入性能
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/AppGallery…
Web集成华为AGC近程配置开发指南:https://developer.huawei.com/…
原文链接:https://developer.huawei.com/…
原作者:Mayism
发表回复