Getting Started
このプラグインのインストール手順と完全なマークダウンガイドを含むセットアップの質問をコピーする。
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.
Install
Section titled “Install”You can use our AI-Assisted Setup to install the plugin. Add the Capgo skills to your AI tool using the following command:
npx skills add https://github.com/Cap-go/capgo-skills --skill capacitor-pluginsThen 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:
bun add @capgo/capacitor-firebase-messagingbunx cap syncImport
Section titled “Import”import { FirebaseMessaging } from '@capgo/capacitor-firebase-messaging';API の概要
API の概要というセクションcheckPermissions
セクションのタイトル “__CAPGO_KEEP_0__ の概要”push通知を受け取るための許可を確認する
On Androidこのメソッドは、Android 13 以降のみで実行する必要があります。
import { FirebaseMessaging } from '@capgo/capacitor-firebase-messaging';
await FirebaseMessaging.checkPermissions();requestPermissions
push通知を受け取るための許可を求めるセクションのタイトル “push通知を受け取るための許可を求める”
push通知を受け取るための許可を求める Android13以上のAndroidでこのメソッドを呼び出す必要があります。
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 通知のデータ フィールドは含まれません。
クリップボードにコピー
import { FirebaseMessaging } from '@capgo/capacitor-firebase-messaging';
await FirebaseMessaging.getDeliveredNotifications();removeDeliveredNotifications
通知画面から特定の通知を削除します。クリップボードにコピー
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();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();Type Reference
型参照PermissionStatus
許可状態export interface PermissionStatus { /** * @since 0.2.2 */ receive: PermissionState;}IsSupportedResult
型参照export interface IsSupportedResult { /** * @since 0.3.1 */ isSupported: boolean;}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
トークン取得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[];}SubscribeToTopicOptions
「トピックへのサブスクリプションオプション」セクションexport interface SubscribeToTopicOptions { /** * The name of the topic to subscribe. * * @since 0.2.2 */ topic: string;}UnsubscribeFromTopicOptions
「トピックからのアンサブスクリプションオプション」セクションexport interface UnsubscribeFromTopicOptions { /** * The name of the topic to unsubscribe from. * * @since 0.2.2 */ topic: string;}CreateChannelOptions
「チャンネル作成オプション」セクションexport type CreateChannelOptions = Channel;DeleteChannelOptions
「チャンネル削除オプション」セクションexport interface DeleteChannelOptions { /** * The channel identifier. * * @since 1.4.0 */ id: string;}ListChannelsResult
「チャンネルの一覧結果」セクションexport interface ListChannelsResult { channels: Channel[];}TokenReceivedListener
「トークン受信リスナー」セクショントークン受信イベントを受け取るコールバック
export type TokenReceivedListener = (event: TokenReceivedEvent) => void;真実の源
「真実の源」セクションこのページはプラグインの設定から生成されています。 src/definitions.tsパブリック API がアップストリームで変更された場合に再度同期を実行してください。
「Getting Started」から続けてください
「Getting Started」から続けてくださいあなたが「を使用している場合 「Getting Started」 ダッシュボードと API の計画と操作を行うには、を接続してください。 API オーバービュー 実装詳細については API の概要を参照してください。 概要 実装詳細については概要を参照してください。 API キー 実装詳細については API キーを参照してください。 デバイス 実装詳細についてはデバイスを参照してください。 バンドル 実装詳細についてはバンドルを参照してください。