跳转至正文

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 以布尔值形式获取指定键的值。
getNumber 以数字形式获取指定键的值。
getString 以字符串形式获取指定键的值。
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()

以布尔值形式获取指定键的值。

import { FirebaseRemoteConfig } from '@capgo/capacitor-firebase-remote-config';

const result = await FirebaseRemoteConfig.getBoolean({ key: 'key-123' });
console.log(result);

getNumber()

以数字形式获取指定键的值。

import { FirebaseRemoteConfig } from '@capgo/capacitor-firebase-remote-config';

const result = await FirebaseRemoteConfig.getNumber({ key: 'key-123' });
console.log(result);

getString()

以字符串形式获取指定键的值。

import { FirebaseRemoteConfig } from '@capgo/capacitor-firebase-remote-config';

const result = await FirebaseRemoteConfig.getString({ key: 'key-123' });
console.log(result);

上表列出了 13 个核心方法。监听器、版本辅助函数以及每个方法的完整约定,请参阅 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 立即发布。

发布 Firebase Remote Config 更改,无需等待应用审核

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

开始使用 Capgo