はじめに
このプラグインのインストール手順と完全なマークダウンガイドを含む設定プロンプトをコピーします。
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
「インストール」のセクション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-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
「requestPermissionsの例」のセクションimport { FirebaseMessaging } from '@capgo/capacitor-firebase-messaging';
const result = await FirebaseMessaging.requestPermissions();console.log(result);例: isSupported
「isSupportedの例」のセクションimport { FirebaseMessaging } from '@capgo/capacitor-firebase-messaging';
const result = await FirebaseMessaging.isSupported();console.log(result);よくある間違い
よくある間違い- 権限: 呼び出す
checkPermissions()thenrequestPermissions()必要な場合にのみ - リスナー: スクリーンがアンマウントされたときにハンドルを削除する
- 真実の源:
src/definitions.tsin the GitHub repo.
API の概要
APIガイドcheckPermissions
「checkPermissions」プッシュ通知を受信するための許可を確認する。
On Androidこのメソッドは、Android 13以上の場合にのみ呼び出す必要があります。
import { FirebaseMessaging } from '@capgo/capacitor-firebase-messaging';
const result = await FirebaseMessaging.checkPermissions();console.log(result);requestPermissions
プッシュ通知を受信するための許可を要求する。プッシュ通知を受信するための許可を要求する。
On 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」セクションプッシュ通知を受信するためにアプリを登録します。 FCMトークンを取得し、Messaging インスタンスに送信するプッシュ メッセージを送信できます。
このメソッドは、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通知のデータフィールドは含まれません。
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」セクション通知チャンネルを作成します。
Only available for Android (SDK 26+).
import { FirebaseMessaging } from '@capgo/capacitor-firebase-messaging';
await FirebaseMessaging.createChannel({ id: 'id-123', name: 'example',});deleteChannel
「チャンネル削除」セクション通知チャンネルの削除
Android (SDK 26+) のみ
import { FirebaseMessaging } from '@capgo/capacitor-firebase-messaging';
await FirebaseMessaging.deleteChannel({ id: 'id-123' });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
「トピックからのアンサインオプション」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の実装詳細について Introduction 導入の詳細については、導入の節を参照してください。 API キー API キーの実装詳細について Devices デバイスの実装詳細について Bundles __CAPGO_KEEP_2__