Skip to content

Getting Started

GitHub

You can use our AI-Assisted Setup to install the plugin. Add the Capgo skills to your AI tool using the following command:

Terminal window
npx skills add https://github.com/Cap-go/capgo-skills --skill capacitor-plugins

Then use the following prompt:

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

If you prefer Manual Setup, install the plugin by running the following commands and follow the platform-specific instructions below:

Terminal window
bun add @capgo/capacitor-firebase-messaging
bunx cap sync
import { FirebaseMessaging } from '@capgo/capacitor-firebase-messaging';

push通知を受け取るための許可を確認する

On Androidこのメソッドは、Android 13 以降のみで実行する必要があります。

import { FirebaseMessaging } from '@capgo/capacitor-firebase-messaging';
await FirebaseMessaging.checkPermissions();

セクションのタイトル “push通知を受け取るための許可を求める”

push通知を受け取るための許可を求める Android13以上のAndroidでこのメソッドを呼び出す必要があります。

import { FirebaseMessaging } from '@capgo/capacitor-firebase-messaging';
await FirebaseMessaging.requestPermissions();

必要なAPIがすべて存在するかどうかを確認します。

常に true AndroidとiOSで

import { FirebaseMessaging } from '@capgo/capacitor-firebase-messaging';
await FirebaseMessaging.isSupported();

アプリをプッシュ通知を受信するように登録します。 FCMトークンを取得し、Messaging インスタンスにプッシュ メッセージを送信できます。

このメソッドは、FCMの自動初期化も再有効化します。

import { FirebaseMessaging } from '@capgo/capacitor-firebase-messaging';
await FirebaseMessaging.getToken();

FCM トークンを削除し、アプリをアンレジスターしてプッシュ通知を受信しないようにします。 ユーザーがログアウトしたときなどに呼び出されることがあります。

import { FirebaseMessaging } from '@capgo/capacitor-firebase-messaging';
await FirebaseMessaging.deleteToken();

通知画面で表示される通知の一覧を取得します。 注: このメソッドは、すべての通知を返します。ローカル通知やFCM通知だけではなく、すべての通知を返します。

Android の場合、FCM 通知のデータ フィールドは含まれません。

クリップボードにコピー

import { FirebaseMessaging } from '@capgo/capacitor-firebase-messaging';
await FirebaseMessaging.getDeliveredNotifications();

クリップボードにコピー

import { FirebaseMessaging } from '@capgo/capacitor-firebase-messaging';
await FirebaseMessaging.removeDeliveredNotifications({} as RemoveDeliveredNotificationsOptions);

removeAllDeliveredNotifications

targetLanguage

通知をすべて削除します。

注意:この操作は、すべての通知を削除し、FCM通知だけを削除するのではなく、ローカル通知も含めます。

import { FirebaseMessaging } from '@capgo/capacitor-firebase-messaging';
await FirebaseMessaging.removeAllDeliveredNotifications();

バックグラウンドでトピックにサブスクライブします。

AndroidとiOSのみで利用可能です。

import { FirebaseMessaging } from '@capgo/capacitor-firebase-messaging';
await FirebaseMessaging.subscribeToTopic({} as SubscribeToTopicOptions);

バックグラウンドでトピックからアンサブスクライブします。

AndroidとiOSのみで利用可能です。

import { FirebaseMessaging } from '@capgo/capacitor-firebase-messaging';
await FirebaseMessaging.unsubscribeFromTopic({} as UnsubscribeFromTopicOptions);

通知チャンネルを作成します。

Android (SDK 26+) でのみ利用可能です。

import { FirebaseMessaging } from '@capgo/capacitor-firebase-messaging';
await FirebaseMessaging.createChannel({} as CreateChannelOptions);

deleteChannel

deleteChannel

通知チャンネルを削除します。

Android (SDK 26+) でのみ利用可能です。

import { FirebaseMessaging } from '@capgo/capacitor-firebase-messaging';
await FirebaseMessaging.deleteChannel({} as DeleteChannelOptions);

listChannels

listChannels

利用可能な通知チャンネルの一覧を表示します。

Android (SDK 26+) でのみ利用可能です。

import { FirebaseMessaging } from '@capgo/capacitor-firebase-messaging';
await FirebaseMessaging.listChannels();

Type Reference

型参照

PermissionStatus

許可状態
export interface PermissionStatus {
/**
* @since 0.2.2
*/
receive: PermissionState;
}

IsSupportedResult

型参照
export interface IsSupportedResult {
/**
* @since 0.3.1
*/
isSupported: boolean;
}
export interface GetTokenOptions {
/**
* Your VAPID public key, which is required to retrieve the current registration token on the web.
*
* Only available for Web.
*/
vapidKey?: string;
/**
* The service worker registration for receiving push messaging.
* If the registration is not provided explicitly, you need to have a `firebase-messaging-sw.js` at your root location.
*
* Only available for Web.
*/
serviceWorkerRegistration?: ServiceWorkerRegistration;
}

GetTokenResult

トークン取得
export interface GetTokenResult {
/**
* @since 0.2.2
*/
token: string;
}

GetDeliveredNotificationsResult

通知取得
export interface GetDeliveredNotificationsResult {
/**
* @since 0.2.2
*/
notifications: Notification[];
}

RemoveDeliveredNotificationsOptions

通知削除オプション
export interface RemoveDeliveredNotificationsOptions {
/**
* @since 0.4.0
*/
notifications: Notification[];
}
export interface SubscribeToTopicOptions {
/**
* The name of the topic to subscribe.
*
* @since 0.2.2
*/
topic: string;
}
export interface UnsubscribeFromTopicOptions {
/**
* The name of the topic to unsubscribe from.
*
* @since 0.2.2
*/
topic: string;
}
export type CreateChannelOptions = Channel;
export interface DeleteChannelOptions {
/**
* The channel identifier.
*
* @since 1.4.0
*/
id: string;
}
export interface ListChannelsResult {
channels: Channel[];
}

トークン受信イベントを受け取るコールバック

export type TokenReceivedListener = (event: TokenReceivedEvent) => void;

このページはプラグインの設定から生成されています。 src/definitions.tsパブリック API がアップストリームで変更された場合に再度同期を実行してください。

「Getting Started」から続けてください

「Getting Started」から続けてください

あなたが「を使用している場合 「Getting Started」 ダッシュボードと API の計画と操作を行うには、を接続してください。 API オーバービュー 実装詳細については API の概要を参照してください。 概要 実装詳細については概要を参照してください。 API キー 実装詳細については API キーを参照してください。 デバイス 実装詳細についてはデバイスを参照してください。 バンドル 実装詳細についてはバンドルを参照してください。