コンテンツにジャンプ

はじめから

ターミナルウィンドウ
bun add @capgo/capacitor-firebase-messaging
bunx cap sync
import { FirebaseMessaging } from '@capgo/capacitor-firebase-messaging';

プッシュ通知を受信するための許可を確認する

オン AndroidAndroid 13 以降では、このメソッドを呼び出す必要があります。

import { FirebaseMessaging } from '@capgo/capacitor-firebase-messaging';
await FirebaseMessaging.checkPermissions();

プッシュ通知を受信するための許可を求める

On Android, this method only needs to be called on Android 13+.

import { FirebaseMessaging } from '@capgo/capacitor-firebase-messaging';
await FirebaseMessaging.requestPermissions();

「isSupported」セクション

必要なすべてのAPIが存在するかどうかを確認します。 true 常に

import { FirebaseMessaging } from '@capgo/capacitor-firebase-messaging';
await FirebaseMessaging.isSupported();

「getToken」セクション

アプリをプッシュ通知を受信できるように登録します。 プッシュメッセージを送信するために使用できるFCMトークンを返します。このメソッドはFCMの自動初期化も再有効化します。

import { FirebaseMessaging } from '@capgo/capacitor-firebase-messaging';
await FirebaseMessaging.getToken();

FCMトークンを削除し、プッシュ通知を受信しないようにアプリをアンリレーションします。 ユーザーがログアウトしたときなどに呼び出されることがあります。

import { FirebaseMessaging } from '@capgo/capacitor-firebase-messaging';
await FirebaseMessaging.deleteToken();

通知画面で表示される通知の一覧を取得します。 注: このメソッドは、FCM通知のみを返しません。ローカル通知も含めて、すべての通知を返します。 Androidの場合、FCM通知のデータフィールドは含まれません。

クリップボードにコピー

「removeDeliveredNotifications」セクション

import { FirebaseMessaging } from '@capgo/capacitor-firebase-messaging';
await FirebaseMessaging.getDeliveredNotifications();

removeDeliveredNotifications

クリップボードにコピー

「removeDeliveredNotifications」セクション

import { FirebaseMessaging } from '@capgo/capacitor-firebase-messaging';
await FirebaseMessaging.removeDeliveredNotifications({} as RemoveDeliveredNotificationsOptions);

通知をすべて削除します。

注: これは、FCM 通知のみを削除するのではなく、すべての通知 (ローカル通知含む) を削除します。

import { FirebaseMessaging } from '@capgo/capacitor-firebase-messaging';
await FirebaseMessaging.removeAllDeliveredNotifications();

バックグラウンドでトピックにサブスクライブします。

Android と iOS のみに対応しています。

import { FirebaseMessaging } from '@capgo/capacitor-firebase-messaging';
await FirebaseMessaging.subscribeToTopic({} as SubscribeToTopicOptions);

バックグラウンドでトピックからアンサブスクライブします。

Android と iOS のみに対応しています。

import { FirebaseMessaging } from '@capgo/capacitor-firebase-messaging';
await FirebaseMessaging.unsubscribeFromTopic({} as UnsubscribeFromTopicOptions);

通知チャンネルの作成

Android用のみ(SDK 26+)。

import { FirebaseMessaging } from '@capgo/capacitor-firebase-messaging';
await FirebaseMessaging.createChannel({} as CreateChannelOptions);

通知チャンネルの削除

Android用のみ(SDK 26+)。

import { FirebaseMessaging } from '@capgo/capacitor-firebase-messaging';
await FirebaseMessaging.deleteChannel({} as DeleteChannelOptions);

通知チャンネルのリスト

Android用のみ(SDK 26+)。

import { FirebaseMessaging } from '@capgo/capacitor-firebase-messaging';
await FirebaseMessaging.listChannels();
export interface PermissionStatus {
/**
* @since 0.2.2
*/
receive: PermissionState;
}
export interface IsSupportedResult {
/**
* @since 0.3.1
*/
isSupported: boolean;
}
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;
}
export interface GetTokenResult {
/**
* @since 0.2.2
*/
token: string;
}

GetDeliveredNotificationsResult

配信された通知結果セクション
export interface GetDeliveredNotificationsResult {
/**
* @since 0.2.2
*/
notifications: Notification[];
}
export interface RemoveDeliveredNotificationsOptions {
/**
* @since 0.4.0
*/
notifications: Notification[];
}
export interface SubscribeToTopicOptions {
/**
* The name of the topic to subscribe.
*
* @since 0.2.2
*/
topic: string;
}
export interface UnsubscribeFromTopicOptions {
/**
* The name of the topic to unsubscribe from.
*
* @since 0.2.2
*/
topic: string;
}
export type CreateChannelOptions = Channel;
export interface DeleteChannelOptions {
/**
* The channel identifier.
*
* @since 1.4.0
*/
id: string;
}
export interface ListChannelsResult {
channels: Channel[];
}

TokenReceivedListener

トークン受信リスナー

トークンを受信したイベントを受け取るコールバック

export type TokenReceivedListener = (event: TokenReceivedEvent) => void;

このページはプラグインから生成されています。 src/definitions.ts上流で公開された API が変更された場合、再度 Sync を実行してください。

Capgo を使用している場合、ダッシュボードと __CAPGO_KEEP_0__ の計画と操作を行うには、接続してください。 Getting Started to plan dashboard and API operations, connect it with API の概要 API の概要の実装詳細について 導入 導入の実装詳細について API のキー API のキーに関する実装詳細について デバイス デバイスの実装詳細について、 バンドル バンドルの実装詳細について。