最近發(fā)現(xiàn)華為AGC遠(yuǎn)程配置服務(wù)開(kāi)始支持Web平臺(tái)了,之前只支持Android版本,期待Web版本很久了,也迫不及待地集成體驗(yàn)了一下,集成的Demo見(jiàn)Github。
集成步驟
1. 開(kāi)通服務(wù)
a) 登錄AGC,創(chuàng)建JS應(yīng)用
b) 開(kāi)通遠(yuǎn)程配置
c) 點(diǎn)擊“添加配置項(xiàng)”,新增遠(yuǎn)程配置的配置項(xiàng)
2. 集成SDK
a) 輸入指令將npm下載到項(xiàng)目中
npm install –save @agconnect/remoteconfig
3. 接入功能
a) 獲取本地配置項(xiàng)
在vue中創(chuàng)建本地配置map
應(yīng)用本地配置
export function applyDefault(map) {
return agconnect.remoteConfig().applyDefault(map);
}
b) 獲取云端配置項(xiàng)
直接調(diào)用fetch接口獲取云端配置
export async function fetch() {
return agconnect.remoteConfig().fetch().then(() => {
return Promise.resolve();
}).catch((err) => {
return Promise.reject(err);
});
}
c) 將配置應(yīng)用到本地,分為實(shí)時(shí)應(yīng)用到本地和生效上次配置兩種。
實(shí)時(shí)應(yīng)用到本地:
直接調(diào)用apply接口:
export function apply() {
return agconnect
.remoteConfig().apply().then((res) => {
return Promise.resolve(res);
}
).catch(error => {
return Promise.reject(error);
});
}
生效上次獲取的配置:
調(diào)用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) 合并本地云端配置
直接調(diào)用getMergedAll接口合并所有配置項(xiàng)
export function getMergedAll() {
return agconnect.remoteConfig().getMergedAll();
}
e) 清除配置項(xiàng)
調(diào)用clearAll接口清除配置項(xiàng)
export function clearAll() {
agconnect.remoteConfig().clearAll();
}
f) 效果展示
點(diǎn)擊獲取,遠(yuǎn)端配置生效合并本地和云端的配置項(xiàng),點(diǎn)擊確定最終顯示出所有的配置項(xiàng)。
想要了解更多相關(guān)內(nèi)容,請(qǐng)參考:
在web平臺(tái)集成華為AGC遠(yuǎn)程配置:https://github.com/AppGalleryConnect/agc-web-demos/tree/master/agc-romoteconfig-demo-javascript
Web集成華為AGC遠(yuǎn)程配置開(kāi)發(fā)指南:https://developer.huawei.com/consumer/cn/doc/development/AppGallery-connect-Guides/agc-remoteconfig-web-getstarted-0000001056501223