跳过内容

入门

GitHub

Install

安装

您可以使用我们的AI辅助设置来安装插件。使用以下命令将Capgo技能添加到您的AI工具中。

终端窗口
npx skills add https://github.com/Cap-go/capgo-skills --skill capacitor-plugins

然后使用以下提示:

Use the `capacitor-plugins` skill from `Cap-go/capgo-skills` to install the `@capgo/capacitor-firebase-functions` plugin in my project.

如果您更喜欢手动设置,请按照以下命令安装插件,并遵循以下平台特定的说明:

终端窗口
bun add @capgo/capacitor-firebase-functions
npx cap sync
import { FirebaseFunctions } from '@capgo/capacitor-firebase-functions';

快速入门

快速入门部分
import { FirebaseFunctions } from '@capgo/capacitor-firebase-functions';
const result = await FirebaseFunctions.callByName({ name: 'myFunction' });
console.log(result);

示例:通过 URL 调用

示例:通过 URL 调用
import { FirebaseFunctions } from '@capgo/capacitor-firebase-functions';
const result = await FirebaseFunctions.callByUrl({
url: 'https://us-central1-my-project.cloudfunctions.net/myFunction',
});
console.log(result);

示例:使用模拟器

示例:使用模拟器
import { FirebaseFunctions } from '@capgo/capacitor-firebase-functions';
await FirebaseFunctions.useEmulator({ host: "127.0.0.1" });

常见问题

常见问题
  • 原生同步: 升级插件后 npx cap sync 真实来源
  • 复制到剪贴板: 信任 src/definitions.ts 在 GitHub 仓库中。

通过名称调用可调用函数。

import { FirebaseFunctions } from '@capgo/capacitor-firebase-functions';
const result = await FirebaseFunctions.callByName({ name: 'myFunction' });
console.log(result);

通过 URL 调用可调用函数。

import { FirebaseFunctions } from '@capgo/capacitor-firebase-functions';
const result = await FirebaseFunctions.callByUrl({
url: 'https://us-central1-my-project.cloudfunctions.net/myFunction',
});
console.log(result);

为应用程序配置使用 Cloud Functions 模拟器的设置。

在 Android 上,必须允许清文本流量。 在 Capacitor 配置中:

{
server: {
cleartext: true
}
}

清文本流量不适合用于生产环境。

import { FirebaseFunctions } from '@capgo/capacitor-firebase-functions';
await FirebaseFunctions.useEmulator({ host: "127.0.0.1" });

类型参考

类型参考

CallByNameOptions

调用ByNameOptions
export interface CallByNameOptions<RequestData = unknown> extends CallOptions<RequestData> {
/**
* The name of the callable function.
*
* @example 'myFunction'
* @since 6.1.0
*/
name: string;
/**
* The region of the callable function.
*
* @example 'us-central1'
* @since 6.1.0
*/
region?: string;
}

CallByNameResult

调用ByNameResult
export type CallByNameResult<ResponseData = unknown> = CallResult<ResponseData>;

CallByUrlOptions

调用ByUrlOptions
export interface CallByUrlOptions<RequestData = unknown> extends CallOptions<RequestData> {
/**
* The URL of the callable function.
*
* @example 'https://us-central1-my-project.cloudfunctions.net/myFunction'
* @since 6.1.0
*/
url: string;
}

CallByUrlResult

CallByUrlResult
export type CallByUrlResult<ResponseData = unknown> = CallResult<ResponseData>;

UseEmulatorOptions

UseEmulatorOptions
export interface UseEmulatorOptions {
/**
* The emulator host without any port or scheme.
*
* Note when using a Android Emulator device: 10.0.2.2 is the special IP address to connect to the 'localhost' of the host computer.
*
* @since 6.1.0
* @example "127.0.0.1"
*/
host: string;
/**
* The emulator port.
*
* @since 6.1.0
* @default 5001
* @example 5001
*/
port?: number;
/**
* The region the callable functions are located in or a custom domain hosting the callable functions.
*
* @example 'us-central1'
* @example 'https://mydomain.com'
*/
regionOrCustomDomain?: string;
}

GetPluginVersionResult

获取插件版本
export interface GetPluginVersionResult {
/**
* The semantic version of this plugin.
*
* @since 8.0.1
*/
version: string;
}

CallResult

CallResult
export interface CallResult<ResponseData = unknown> {
/**
* The result of the callable function.
*
* @since 6.1.0
*/
data: ResponseData;
}

真实来源

真实来源

本页面是根据插件生成的 src/definitions.ts. 重新同步公共API时,源代码发生了变化。

继续从 Getting Started

标题:继续从 Getting Started

如果您正在使用 开始使用 规划仪表板和 API 操作,请将其连接到 API 概述 查看 API 概述 中的实现细节 介绍 查看介绍 中的实现细节 API 密钥 查看 API 密钥 中的实现细节 设备 为设备的实现细节,和 捆绑包 为捆绑包的实现细节。