最近發現華為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