指南
如何在 Capacitor 中使用 Firebase Remote Config
使用 @capgo/capacitor-firebase-remote-config
适用于 Firebase Remote Config 的 Capacitor 插件
安装
bun add @capgo/capacitor-firebase-remote-config
bunx cap sync
bunx cap sync 将插件的原生 code 复制到你的原生项目中。每次升级插件后都要重新运行。
导入
import { FirebaseRemoteConfig } from '@capgo/capacitor-firebase-remote-config';
API 概览
| 方法 | 描述 |
|---|---|
activate |
将最后一次获取的配置提供给 getter 使用。 |
fetchAndActivate |
执行 fetch 和 activate 操作。 |
fetchConfig |
从 Remote Config 服务中获取并缓存配置。 |
getBoolean |
以布尔值形式获取指定 key 的值。 |
getNumber |
以数字形式获取指定 key 的值。 |
getString |
以字符串形式获取指定 key 的值。 |
getAll |
获取 Remote Config 服务中的所有值。 |
getInfo |
获取最后一次 fetch 操作的信息。 |
setMinimumFetchInterval |
设置最小获取间隔。 |
setDefaults |
在默认命名空间配置中,为参数键值对设置默认配置。 |
setSettings |
设置远程配置参数。 |
addConfigUpdateListener |
添加配置更新事件的监听器。 |
removeConfigUpdateListener |
移除配置更新事件的监听器。 |
示例
activate()
将最后一次获取的配置提供给 getter 使用。
import { FirebaseRemoteConfig } from '@capgo/capacitor-firebase-remote-config';
await FirebaseRemoteConfig.activate();
fetchAndActivate()
执行 fetch 和 activate 操作。
import { FirebaseRemoteConfig } from '@capgo/capacitor-firebase-remote-config';
await FirebaseRemoteConfig.fetchAndActivate();
fetchConfig()
从 Remote Config 服务中获取并缓存配置。
import { FirebaseRemoteConfig } from '@capgo/capacitor-firebase-remote-config';
await FirebaseRemoteConfig.fetchConfig();
getBoolean()
以布尔值形式获取指定 key 的值。
import { FirebaseRemoteConfig } from '@capgo/capacitor-firebase-remote-config';
const result = await FirebaseRemoteConfig.getBoolean({ key: 'key-123' });
console.log(result);
getNumber()
以数字形式获取指定 key 的值。
import { FirebaseRemoteConfig } from '@capgo/capacitor-firebase-remote-config';
const result = await FirebaseRemoteConfig.getNumber({ key: 'key-123' });
console.log(result);
getString()
以字符串形式获取指定 key 的值。
import { FirebaseRemoteConfig } from '@capgo/capacitor-firebase-remote-config';
const result = await FirebaseRemoteConfig.getString({ key: 'key-123' });
console.log(result);
上表列出了 13 个核心方法。有关 Listener 和版本辅助函数以及每个方法的完整契约,请参阅 GitHub 仓库.
完整参考
继续学习 使用 @capgo/capacitor-firebase-remote-config
如果你正在使用 使用 @capgo/capacitor-firebase-remote-config 要规划原生插件工作,请将其连接到 Capgo 插件目录 用于 Capgo 插件目录中的产品工作流, 由 Capgo 提供的 Capacitor 插件 有关 Capgo 编写的 Capacitor 插件实现细节, 添加或更新插件 关于“添加或更新插件”中的实现细节, Ionic Enterprise 插件替代方案 了解 Ionic Enterprise 插件替代方案的产品工作流,以及 Capgo Native Build 关于 Capgo Native Builds 中的产品工作流。