はじめに
このプラグインのインストール手順と完全なマークダウンガイドを含むセットアッププロンプトをコピーします。
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セットアップを使用する場合は、以下のコマンドを実行してプラグインをインストールし、以下のプラットフォーム固有の指示に従ってください。
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 26以降のみ利用可能です (SDK )。
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キー APIキーに関する実装詳細についてはこちら デバイス デバイスに関する実装詳細についてはこちら バンドル バンドルに関する実装詳細についてはこちら