跳过内容

开始

GitHub

安装

安装

您可以使用我们的AI辅助设置来安装插件。使用以下命令将Capgo技能添加到您的AI工具中:

终端窗口
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.

如果您prefer手动设置,安装插件并运行以下命令并遵循以下平台特定的说明:

终端窗口
bun add @capgo/capacitor-firebase-messaging
bunx cap sync

导入

导入
import { FirebaseMessaging } from '@capgo/capacitor-firebase-messaging';

检查接收推送通知的权限.

开启 Android在Android 13+上调用此方法时,只需调用此方法.

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

请求接收推送通知的权限.

开启 安卓, 只需在 Android 13+ 上调用此方法。

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

检查所有所需 API 是否存在。

总是返回 true 在安卓和 iOS 上。

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

注册应用以接收推送通知。 返回一个 FCM 令牌,可用于向 Messaging 实例发送推送消息。 此方法还重新启用 FCM 自动初始化。

复制到剪贴板

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

注销 FCM token 并取消应用程序的注册以停止接收推送通知。 可以在用户注销时调用。

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

获取可在通知屏幕上显示的通知列表。 注意:此方法将返回所有已交付的通知,包括本地通知,而不仅仅是 FCM 通知。 在 Android 上,FCM 通知的数据字段将不会包含在内。

复制到剪贴板

Section titled “removeDeliveredNotifications”

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

removeDeliveredNotifications

复制到剪贴板

Section titled “removeAllDeliveredNotifications”

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

removeAllDeliveredNotifications

复制到剪贴板

清除所有通知。

注意:此操作将清除所有已送达的通知,包括本地通知和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();

类型参考

类型参考

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上游发生变化时,请重新运行同步。

从开始就继续

从开始就继续

如果您正在使用 开始 规划仪表板和API操作时,请将其连接到 API概述 为实现细节在API概述中 简介 为实现细节在简介中 API密钥 为实现细节在API密钥中 设备 为实现细节在设备中,和 捆绑包 为实现细节在捆绑包中。