スタートガイド
インストール手順と、このプラグインの完全なMarkdownガイドを含むセットアッププロンプトをコピーします。
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.
インストール
「インストール」セクション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.手動セットアップを希望する場合は、以下のコマンドを実行してプラグインをインストールし、下記のプラットフォーム別の手順に従ってください:
bun add @capgo/capacitor-firebase-messagingnpx cap syncインポート
「インポート」セクションimport { FirebaseMessaging } from '@capgo/capacitor-firebase-messaging';クイックスタート
「クイックスタート」セクションimport { FirebaseMessaging } from '@capgo/capacitor-firebase-messaging';
const result = await FirebaseMessaging.checkPermissions();console.log(result);例: requestPermissions
「Example: requestPermissions」セクションimport { FirebaseMessaging } from '@capgo/capacitor-firebase-messaging';
const result = await FirebaseMessaging.requestPermissions();console.log(result);例: isSupported
「Example: isSupported」セクションimport { FirebaseMessaging } from '@capgo/capacitor-firebase-messaging';
const result = await FirebaseMessaging.isSupported();console.log(result);よくある落とし穴
「よくある落とし穴」セクション- 権限:呼び出し
checkPermissions()その後requestPermissions()必要に応じて。 - リスナー: 画面がアンマウントされたらハンドルを削除します。
- 信頼できる情報源: 信頼
src/definitions.tsGitHub リポジトリ内。
API の概要
「API 概要」セクションcheckPermissions
「checkPermissions」セクションプッシュ通知の受信許可を確認します。
オンラインに Androidでは, このメソッドは Android 13 以降でのみ呼び出す必要があります。
import { FirebaseMessaging } from '@capgo/capacitor-firebase-messaging';
const result = await FirebaseMessaging.checkPermissions();console.log(result);requestPermissions
「requestPermissions」セクションプッシュ通知の受信許可をリクエストします。
オンラインに Androidでは, このメソッドは Android 13 以降でのみ呼び出す必要があります。
import { FirebaseMessaging } from '@capgo/capacitor-firebase-messaging';
const result = await FirebaseMessaging.requestPermissions();console.log(result);isSupported
「isSupported」セクション必要なすべてのAPIが存在するか確認します。
常に返します true Android と iOS で。
import { FirebaseMessaging } from '@capgo/capacitor-firebase-messaging';
const result = await FirebaseMessaging.isSupported();console.log(result);getToken
「getToken」セクションプッシュ通知を受信するためにアプリを登録します。 その Messaging インスタンスにプッシュメッセージを送信するために使用できる FCM トークンを返します。
このメソッドはFCMの自動初期化も再度有効にします。
import { FirebaseMessaging } from '@capgo/capacitor-firebase-messaging';
const result = await FirebaseMessaging.getToken();// The result holds sensitive values: use it without logging it.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';
const result = await FirebaseMessaging.getDeliveredNotifications();console.log(result);removeDeliveredNotifications
「removeDeliveredNotifications」セクション通知画面から特定の通知を削除します。
import { FirebaseMessaging } from '@capgo/capacitor-firebase-messaging';
await FirebaseMessaging.removeDeliveredNotifications({ notifications: [] });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({ topic: 'topic' });unsubscribeFromTopic
「unsubscribeFromTopic」セクションバックグラウンドでトピックの購読を解除します。
Android と iOS でのみ利用できます。
import { FirebaseMessaging } from '@capgo/capacitor-firebase-messaging';
await FirebaseMessaging.unsubscribeFromTopic({ topic: 'topic' });createChannel
「createChannel」セクション通知チャンネルを作成します。
Android のみ利用可能(SDK 26以降)。
import { FirebaseMessaging } from '@capgo/capacitor-firebase-messaging';
await FirebaseMessaging.createChannel({ id: 'id-123', name: 'example',});deleteChannel
「deleteChannel」セクション通知チャンネルを削除します。
Android のみ利用可能(SDK 26以降)。
import { FirebaseMessaging } from '@capgo/capacitor-firebase-messaging';
await FirebaseMessaging.deleteChannel({ id: 'id-123' });listChannels
「listChannels」セクション利用可能な通知チャンネルを一覧表示します。
Android のみ利用可能(SDK 26以降)。
import { FirebaseMessaging } from '@capgo/capacitor-firebase-messaging';
const result = await FirebaseMessaging.listChannels();console.log(result);型リファレンス
「型リファレンス」セクション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」というセクションtoken received イベントを受け取るコールバック。
export type TokenReceivedListener = (event: TokenReceivedEvent) => void;Source of Truth
「Source Of Truth」セクションこのページはプラグインの src/definitions.tsから生成されています。upstream で公開 API が変更されたら、再度 sync を実行してください。
Getting Startedの続きを進める
「Getting Started からの続き」セクション使用している場合 スタートガイド ダッシュボードと API の運用を計画するには、これを次と連携させます API の概要 「API の概要」の実装の詳細については、 はじめに 「はじめに」における実装の詳細については、 API キー API Keys の実装の詳細については、 デバイス Devices の実装詳細については、および Bundle Bundlesの実装詳細については