コンテンツにスキップ

はじめに

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

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

On Androidこのメソッドは、Android 13 以降のみ呼び出す必要があります。

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

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

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

deleteToken

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

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();

トピックのサブスクリプションをバックグラウンドで実行します。

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[];
}

RemoveDeliveredNotificationsOptions

配信された通知削除オプション
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[];
}

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

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

真実の源

真実の源

このページはプラグインから生成されています。 src/definitions.ts. upstreamの公開 API が変更されたときに、再度同期を実行してください。