メインコンテンツへスキップ

はじめに

GitHub

AIアシストセットアップを使ってプラグインをインストールできます。以下のコマンドで、お使いのAIツールに Capgo スキルを追加してください:

ターミナルウィンドウ
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';

クイックスタート

「Quick start」セクション
import { FirebaseFunctions } from '@capgo/capacitor-firebase-functions';
const result = await FirebaseFunctions.callByName({ name: 'myFunction' });
console.log(result);
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" });

よくある落とし穴

「Common pitfalls」セクション
  • Native sync: 実行 npx cap sync プラグインのアップグレード後。
  • 信頼できる唯一の情報源: 信頼 src/definitions.ts の GitHub リポジトリ内。

関数名を指定してCallable関数を呼び出します。

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

URLを指定してCallable関数を呼び出します。

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では、cleartext trafficを許可する必要があります。Capacitorの設定は以下の通りです:

{
server: {
cleartext: true
}
}

なお、cleartext trafficは本番環境での使用を想定していません。

import { FirebaseFunctions } from '@capgo/capacitor-firebase-functions';
await FirebaseFunctions.useEmulator({ host: "127.0.0.1" });
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;
}
export type CallByNameResult<ResponseData = unknown> = CallResult<ResponseData>;
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;
}
export type CallByUrlResult<ResponseData = unknown> = CallResult<ResponseData>;
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;
}
export interface GetPluginVersionResult {
/**
* The semantic version of this plugin.
*
* @since 8.0.1
*/
version: string;
}
export interface CallResult<ResponseData = unknown> {
/**
* The result of the callable function.
*
* @since 6.1.0
*/
data: ResponseData;
}

このページはプラグインの src/definitions.tsから生成されています。上流の公開 API が変更された場合は、再度 sync を実行してください。

Getting Started から続ける

「Getting Started」の続き

以下を使用している場合: はじめに ダッシュボードと API の操作を計画するには、以下と連携してください API の概要 API Overview の実装の詳細については、 はじめに Introduction の実装の詳細については、 API キー API Keysの実装詳細については、 デバイス Devicesにおける実装の詳細については、 バンドル Bundlesにおける実装の詳細については、