开始
复制一个设置提示,包含安装步骤和该插件的完整Markdown指南。
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 syncimport { FirebaseMessaging } from '@capgo/capacitor-firebase-messaging';API Overview
Section titled “API Overview”checkPermissions
Section titled “checkPermissions”检查接收推送通知的权限。
开启 Android在 Android 13+ 上调用此方法。
import { FirebaseMessaging } from '@capgo/capacitor-firebase-messaging';
await FirebaseMessaging.checkPermissions();requestPermissions
Section titled “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 自动初始化。
__CAPGO_KEEP_0__
import { FirebaseMessaging } from '@capgo/capacitor-firebase-messaging';
await FirebaseMessaging.getToken();deleteToken
标题:删除令牌删除 FCM 令牌并注销应用以停止接收推送通知。 可以在用户注销时调用。
import { FirebaseMessaging } from '@capgo/capacitor-firebase-messaging';
await FirebaseMessaging.deleteToken();getDeliveredNotifications
标题:获取已送达通知获取通知屏幕上可见的通知列表。
注意:此方法将返回所有已送达通知,包括本地通知,而不是仅限 FCM 通知。
在 Android 上,FCM 通知的数据字段将不会包含。
import { FirebaseMessaging } from '@capgo/capacitor-firebase-messaging';
await FirebaseMessaging.getDeliveredNotifications();removeDeliveredNotifications
标题:删除已送达通知从通知屏幕中删除特定通知。
import { FirebaseMessaging } from '@capgo/capacitor-firebase-messaging';
await FirebaseMessaging.removeDeliveredNotifications({} as RemoveDeliveredNotificationsOptions);removeAllDeliveredNotifications
Section titled “removeAllDeliveredNotifications”从通知屏幕中移除所有通知。
注意:此操作将移除所有已送达的通知,包括本地通知和FCM通知。
import { FirebaseMessaging } from '@capgo/capacitor-firebase-messaging';
await FirebaseMessaging.removeAllDeliveredNotifications();subscribeToTopic
Section titled “subscribeToTopic”在后台订阅主题。
仅适用于Android和iOS。
import { FirebaseMessaging } from '@capgo/capacitor-firebase-messaging';
await FirebaseMessaging.subscribeToTopic({} as SubscribeToTopicOptions);unsubscribeFromTopic
Section titled “unsubscribeFromTopic”在后台取消订阅主题。
仅适用于Android和iOS。
import { FirebaseMessaging } from '@capgo/capacitor-firebase-messaging';
await FirebaseMessaging.unsubscribeFromTopic({} as UnsubscribeFromTopicOptions);createChannel
创建频道创建通知频道
仅适用于 Android (SDK 26+)
import { FirebaseMessaging } from '@capgo/capacitor-firebase-messaging';
await FirebaseMessaging.createChannel({} as CreateChannelOptions);deleteChannel
删除频道删除通知频道
仅适用于 Android (SDK 26+)
import { FirebaseMessaging } from '@capgo/capacitor-firebase-messaging';
await FirebaseMessaging.deleteChannel({} as DeleteChannelOptions);listChannels
获取通知频道列表获取可用通知频道列表
仅适用于 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
TokenReceivedListener接收到的令牌事件回调
export type TokenReceivedListener = (event: TokenReceivedEvent) => void;本页面是由插件生成的。 src/definitions.ts当公共 API 上游更改时,请重新运行同步。
从开始阶段继续
Section titled “从开始阶段继续”如果您正在使用 开始阶段 来规划仪表板和 API 操作,请将其连接 API概述 为API概述的实现细节 介绍 为介绍的实现细节 API密钥 为API密钥的实现细节 设备 为设备的实现细节,和 捆绑包 为捆绑包的实现细节