跳转至正文

Firebase Remote Config Capacitor 插件

适用于 Firebase Remote Config 的 Capacitor 插件

安装

bun add @capgo/capacitor-firebase-remote-config bunx cap sync
npm、pnpm 或 yarn
  • npm install @capgo/capacitor-firebase-remote-config
  • pnpm add @capgo/capacitor-firebase-remote-config
  • yarn add @capgo/capacitor-firebase-remote-config

指南

如何在 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 中的产品工作流。

常见问题

Firebase Remote Config 插件常见问题

如何在 Capacitor 应用中安装 Firebase Remote Config 插件?

运行 "bun add @capgo/capacitor-firebase-remote-config"(或 "npm install @capgo/capacitor-firebase-remote-config"),然后运行 "bunx cap sync",使 iOS 和 Android 项目同步原生 code。最后在你的应用 code 中从 "@capgo/capacitor-firebase-remote-config" 导入即可。

@capgo/capacitor-firebase-remote-config 是否支持 React、Vue 和 Angular?

支持。Firebase Remote Config 是一个 Capacitor 包,因此它支持任何在 Capacitor 中运行的 Web 框架,包括 Ionic、React、Vue、Angular、Svelte 以及原生 JavaScript。

@capgo/capacitor-firebase-remote-config 支持哪个版本的 Capacitor?

Capgo 插件跟随 Capacitor 的主版本号:插件主版本要与你的 Capacitor 主版本匹配(例如插件 v8 对应 Capacitor 8)。GitHub README 里的兼容性表格列出了仍在维护的版本。

@capgo/capacitor-firebase-remote-config 是免费开源的吗?

是的。code 的源码已在 GitHub 公开,地址为 https://github.com/Cap-go/capacitor-firebase/tree/main/packages/remote-config,且可从 npm 免费安装。欢迎提交 Bug 报告和 Pull Request。

使用 Firebase Remote Config 的 code 能在不经过 App Store 审核的情况下更新吗?

安装或升级插件会改动原生 code,所以需要重新构建商店版本。之后,调用该插件的 JavaScript、HTML 和 CSS 改动就能通过 Capgo live updates 即时发布。

无需等待 App Store 审核,即可即时推送 Firebase Remote Config 配置变更

只要插件已包含在商店构建中,Capgo live updates 就能在几分钟内将你的 JavaScript、HTML 和 CSS 更改推送给用户。

立即开始使用 Capgo