はじめに
このプラグインのインストールステップとフルマークダウンガイドのセットアッププロンプトをコピーする
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.
インストール
「インストール」のセクションbun add @capgo/capacitor-firebase-messagingbunx cap syncインポート
「インポート」のセクションimport { FirebaseMessaging } from '@capgo/capacitor-firebase-messaging';APIの概要
「APIの概要」のセクションcheckPermissions
「checkPermissions」セクションプッシュ通知を受信するための許可を確認します。
On 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
deleteTokenFCM トークンを削除して、アプリをプッシュ通知を受信しないようにしてください。 ユーザーがログアウトしたときなどに呼び出すことができます。
import { FirebaseMessaging } from '@capgo/capacitor-firebase-messaging';
await FirebaseMessaging.deleteToken();getDeliveredNotifications
getDeliveredNotifications通知が表示されている画面の通知の一覧を取得します。
注意: このAPIは、すべての通知を返します。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通知が表示されている画面からすべての通知を削除します。
注意: このAPIは、すべての通知を削除します。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
サポートされている結果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
「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. upstreamの公開 API が変更されたときに、再度同期を実行してください。