はじめに
このプラグインのインストール手順と全マークダウンガイドを含む設定プロンプトをコピーする。
Set up this Capacitor plugin in the project.
Use the package manager already used by the project.
Install these package(s): `@capgo/capacitor-firebase-messaging`
Run the required Capacitor sync/update step after installation.
Read this markdown guide for the full setup steps: https://raw.githubusercontent.com/Cap-go/website/refs/heads/main/apps/docs/src/content/docs/docs/plugins/firebase-messaging/getting-started.mdx
Use that guide for platform-specific steps, native file edits, permissions, config changes, imports, and usage setup.
If that guide references other docs pages, read them too.
インストール
「インストール」のセクションCapgoの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-messaging` plugin in my project.Manual Setupを使用する場合は、以下のコマンドを実行してプラグインをインストールし、以下のプラットフォーム固有の指示に従ってください。
bun add @capgo/capacitor-firebase-messagingbunx cap syncインポート
「インポート」のセクションimport { FirebaseMessaging } from '@capgo/capacitor-firebase-messaging';APIの概要
「APIの概要」のセクションcheckPermissions
「checkPermissions」のセクションプッシュ通知を受信するための権限を確認してください。
オン Androidこのメソッドは、Android 13以上の場合にのみ呼び出す必要があります。
import { FirebaseMessaging } from '@capgo/capacitor-firebase-messaging';
await FirebaseMessaging.checkPermissions();requestPermissions
「requestPermissions」セクションプッシュ通知を受信するための許可を求めます。
「On」 「Android」このメソッドは、Android 13 以降のみで実行する必要があります。
import { FirebaseMessaging } from '@capgo/capacitor-firebase-messaging';
await FirebaseMessaging.requestPermissions();isSupported
「isSupported」セクション必要な API がすべて存在するかどうかを確認します。
常に true Android と iOS で返されます。
import { FirebaseMessaging } from '@capgo/capacitor-firebase-messaging';
await FirebaseMessaging.isSupported();getToken
「getToken」セクションプッシュ通知を受信するアプリを登録します。 FCMトークンを取得し、Messaging インスタンスにプッシュメッセージを送信できます。
このメソッドは、FCM 自動初期化も再有効化します。
import { FirebaseMessaging } from '@capgo/capacitor-firebase-messaging';
await FirebaseMessaging.getToken();deleteToken
「deleteToken」セクションFCM トークンを削除してプッシュ通知を受信しないようにアプリをアンレジストします。 ユーザーがログアウトしたときなどに呼び出すことができます。
import { FirebaseMessaging } from '@capgo/capacitor-firebase-messaging';
await FirebaseMessaging.deleteToken();getDeliveredNotifications
「getDeliveredNotifications」セクション通知画面で表示されている通知の一覧を取得します。
注意: このメソッドは、すべての通知を返します。ローカル通知やFCM通知だけではなく、すべての通知を返します。
Androidの場合、FCM通知のdataフィールドは含まれません。
import { FirebaseMessaging } from '@capgo/capacitor-firebase-messaging';
await FirebaseMessaging.getDeliveredNotifications();removeDeliveredNotifications
「removeDeliveredNotifications」セクション通知画面から特定の通知を削除します。
import { FirebaseMessaging } from '@capgo/capacitor-firebase-messaging';
await FirebaseMessaging.removeDeliveredNotifications({} as RemoveDeliveredNotificationsOptions);removeAllDeliveredNotifications
「removeAllDeliveredNotifications」セクション通知画面からすべての通知を削除します。
注:この機能は、FCM通知だけでなく、ローカル通知もすべて削除します。
import { FirebaseMessaging } from '@capgo/capacitor-firebase-messaging';
await FirebaseMessaging.removeAllDeliveredNotifications();subscribeToTopic
「subscribeToTopic」セクションバックグラウンドでトピックにサブスクライブします。
AndroidおよびiOSのみで利用可能です。
import { FirebaseMessaging } from '@capgo/capacitor-firebase-messaging';
await FirebaseMessaging.subscribeToTopic({} as SubscribeToTopicOptions);unsubscribeFromTopic
「unsubscribeFromTopic」セクションバックグラウンドでトピックからアンサブスクライブします。
AndroidおよびiOSのみ対応。
import { FirebaseMessaging } from '@capgo/capacitor-firebase-messaging';
await FirebaseMessaging.unsubscribeFromTopic({} as UnsubscribeFromTopicOptions);createChannel
セクション:createChannel通知チャンネルを作成します。
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();型参照
「型参照」PermissionStatus
「PermissionStatus」export interface PermissionStatus { /** * @since 0.2.2 */ receive: PermissionState;}IsSupportedResult
「IsSupportedResult」export interface IsSupportedResult { /** * @since 0.3.1 */ isSupported: boolean;}GetTokenOptions
「GetTokenOptions」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
「GetTokenResult」export interface GetTokenResult { /** * @since 0.2.2 */ token: string;}GetDeliveredNotificationsResult
「GetDeliveredNotificationsResult」セクションのタイトルexport interface GetDeliveredNotificationsResult { /** * @since 0.2.2 */ notifications: Notification[];}RemoveDeliveredNotificationsOptions
「RemoveDeliveredNotificationsOptions」セクションのタイトルexport interface RemoveDeliveredNotificationsOptions { /** * @since 0.4.0 */ notifications: Notification[];}SubscribeToTopicOptions
「SubscribeToTopicOptions」セクションのタイトルexport interface SubscribeToTopicOptions { /** * The name of the topic to subscribe. * * @since 0.2.2 */ topic: string;}UnsubscribeFromTopicOptions
「UnsubscribeFromTopicOptions」セクションのタイトルexport interface UnsubscribeFromTopicOptions { /** * The name of the topic to unsubscribe from. * * @since 0.2.2 */ topic: string;}CreateChannelOptions
「CreateChannelOptions」セクションのタイトルexport type CreateChannelOptions = Channel;DeleteChannelOptions
「DeleteChannelOptions」セクションのタイトルexport interface DeleteChannelOptions { /** * The channel identifier. * * @since 1.4.0 */ id: string;}ListChannelsResult
「ListChannelsResult」セクションexport interface ListChannelsResult { channels: Channel[];}TokenReceivedListener
「TokenReceivedListener」セクショントークン受信イベントを受信するコールバック
export type TokenReceivedListener = (event: TokenReceivedEvent) => void;真実の源
「真実の源」セクションこのページはプラグインの src/definitions.tsパブリックAPIがアップストリームで変更されたときに再度Syncを実行してください。
Getting Startedから続けてください
「Getting Startedから続けてください」セクションCapacitorを使用している場合 始め方 を計画用ダッシュボードとAPIの運用に接続する APIの概要 APIの概要の実装詳細について 導入 導入の実装詳細について APIのキー APIのキーに関する実装詳細について デバイス デバイスに関する実装詳細について バンドル バンドルに関する実装詳細について