1.0.9 • Published 2 years ago
@hw-agconnect/remoteconfig-ohos v1.0.9
AGConnect Remote Configuration
简介
您如果想打造一个出色的应用取得商业成功,需要持续为用户提供新鲜内容、新鲜功能,快速响应用户不断变化的需求和体验喜好,需要尽可能地为不同的目标用户提供差异化的用户体验。使用AppGallery Connect(简称AGC)的远程配置,您的应用即可无需升级,也可以在云端灵活修改应用的行为和外观,从而快速响应用户的需求。
- 支持获取云端配置信息
- 支持应用本地配置信息
下载安装
ohpm install @hw-agconnect/remoteconfig-ohos
OpenHarmony ohpm 环境配置等更多内容,请参考如何安装 OpenHarmony ohpm 包
使用说明
import agconnect from "@hw-agconnect/api-ohos";
import "@hw-agconnect/remoteconfig-ohos";
import "@hw-agconnect/core-ohos";
需要权限
ohos.permission.INTERNET
使用示例
初始化
在您的项目中导入agc组件。
import agconnect from "@hw-agconnect/api-ohos"; import "@hw-agconnect/remoteconfig-ohos"; import "@hw-agconnect/core-ohos";
在您的应用初始化阶段使用context初始化SDK,推荐在MainAbility 的onCreate中进行。
//初始化SDK onCreate(want, launchParam) { //务必保证resources/rawfile中包含agconnect-services.json文件 agconnect.instance().init(this.context.getApplicationContext()); } agconnect.remoteConfig().initialized();
获取云端配置参数并应用
同步参数
agconnect.remoteConfig().fetch().then(configValue => { // configValue }).catch(error => { // error });
应用参数
agconnect.remoteConfig().apply(configValue);
应用本地参数
let map = new Map();
map.set("cn_key_local_01", "cn_value_local_01");
map.set("cn_key_local_02", "cn_value_local_02");
map.set("cn_key_local_03_number", 100);
map.set("cn_key_local_04_boolean", true);
map.set("cn_key_both", "cn_value_local");
agconnect.remoteConfig().applyDefault(map).then(() => {
}).catch(() => {
});
获取参数
- 获取单个参数
let cn_key_01 = agconnect.remoteConfig().getValueAsString("key_01");
获取所有参数列表
let allMap = agconnect.remoteConfig().getMergedAll(); allMap.forEach((value, key) => { })
约束与限制
在下述版本验证通过: DevEco Studio: 3.1 Beta2(3.1.0.400), SDK: API9 Release(3.2.11.9)
License
remoteconfig-ohos sdk is licensed under the: "ISC"