Mulai
Copy sebuah prompt pengaturan dengan langkah instalasi dan panduan markdown lengkap untuk plugin ini.
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 Ringkasan
Ringkasan APIcheckPermissions
Bagian berjudul ācheckPermissionsāPeriksa izin untuk menerima push notifikasi.
Aktifkan AndroidMetode ini hanya perlu dipanggil pada Android 13+.
import { FirebaseMessaging } from '@capgo/capacitor-firebase-messaging';
await FirebaseMessaging.checkPermissions();requestPermissions
Bagian berjudul ārequestPermissionsāMinta izin untuk menerima push notifikasi.
Aktifkan AndroidMetode ini hanya perlu dipanggil pada Android 13+.
import { FirebaseMessaging } from '@capgo/capacitor-firebase-messaging';
await FirebaseMessaging.requestPermissions();isSupported
Bagian berjudul āisSupportedāMengecek apakah semua API yang dibutuhkan ada.
Selalu mengembalikan true pada Android dan iOS.
import { FirebaseMessaging } from '@capgo/capacitor-firebase-messaging';
await FirebaseMessaging.isSupported();getToken
Bagian berjudul āgetTokenāDaftarkan aplikasi untuk menerima notifikasi push. Mengembalikan token FCM yang dapat digunakan untuk mengirim pesan push ke instance Messaging tersebut.
Metode ini juga mengaktifkan ulang FCM auto-init.
import { FirebaseMessaging } from '@capgo/capacitor-firebase-messaging';
await FirebaseMessaging.getToken();deleteToken
Bagian berjudul ādeleteTokenāHapus token FCM dan daftarkan aplikasi untuk berhenti menerima notifikasi push. Dapat dipanggil, misalnya, ketika pengguna keluar.
import { FirebaseMessaging } from '@capgo/capacitor-firebase-messaging';
await FirebaseMessaging.deleteToken();getDeliveredNotifications
Bagian berjudul āgetDeliveredNotificationsāDapatkan daftar notifikasi yang terlihat di layar notifikasi.
Perlu diingat: Ini akan mengembalikan semua notifikasi yang telah terkirim, termasuk notifikasi lokal, dan bukan hanya notifikasi FCM.
Pada Android, bidang data notifikasi FCM TIDAK akan termasuk.
import { FirebaseMessaging } from '@capgo/capacitor-firebase-messaging';
await FirebaseMessaging.getDeliveredNotifications();removeDeliveredNotifications
Bagian berjudul āremoveDeliveredNotificationsāHapus notifikasi tertentu dari layar notifikasi.
import { FirebaseMessaging } from '@capgo/capacitor-firebase-messaging';
await FirebaseMessaging.removeDeliveredNotifications({} as RemoveDeliveredNotificationsOptions);removeAllDeliveredNotifications
Bagian berjudul āremoveAllDeliveredNotificationsāHapus semua notifikasi dari layar notifikasi.
Perlu diingat: Ini akan menghapus semua notifikasi yang telah terkirim, termasuk notifikasi lokal, dan bukan hanya notifikasi FCM.
import { FirebaseMessaging } from '@capgo/capacitor-firebase-messaging';
await FirebaseMessaging.removeAllDeliveredNotifications();subscribeToTopic
Bagian berjudul āsubscribeToTopicāMengikuti topik di latar belakang.
Hanya tersedia untuk Android dan iOS.
import { FirebaseMessaging } from '@capgo/capacitor-firebase-messaging';
await FirebaseMessaging.subscribeToTopic({} as SubscribeToTopicOptions);unsubscribeFromTopic
Bagian berjudul āunsubscribeFromTopicāMenghentikan pengikutan topik di latar belakang.
Hanya tersedia untuk Android dan iOS.
import { FirebaseMessaging } from '@capgo/capacitor-firebase-messaging';
await FirebaseMessaging.unsubscribeFromTopic({} as UnsubscribeFromTopicOptions);createChannel
Bagian berjudul ācreateChannelāMembuat saluran peringatan.
Hanya tersedia untuk Android (SDK 26+).
import { FirebaseMessaging } from '@capgo/capacitor-firebase-messaging';
await FirebaseMessaging.createChannel({} as CreateChannelOptions);deleteChannel
Bagian berjudul ādeleteChannelāHapus saluran pemberitahuan.
Hanya tersedia untuk Android (SDK 26+).
import { FirebaseMessaging } from '@capgo/capacitor-firebase-messaging';
await FirebaseMessaging.deleteChannel({} as DeleteChannelOptions);listChannels
Bagian berjudul ālistChannelsāDaftar saluran pemberitahuan yang tersedia.
Hanya tersedia untuk Android (SDK 26+).
import { FirebaseMessaging } from '@capgo/capacitor-firebase-messaging';
await FirebaseMessaging.listChannels();Referensi Tipe
Bagian berjudul āReferensi TipeāPermissionStatus
Bagian berjudul āStatus Izināexport interface PermissionStatus { /** * @since 0.2.2 */ receive: PermissionState;}IsSupportedResult
Bagian berjudul āIsSupportedResultāexport interface IsSupportedResult { /** * @since 0.3.1 */ isSupported: boolean;}GetTokenOptions
Bagian berjudul ā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
Bagian berjudul āGetTokenResultāexport interface GetTokenResult { /** * @since 0.2.2 */ token: string;}GetDeliveredNotificationsResult
Bagian berjudul āGetDeliveredNotificationsResultāexport interface GetDeliveredNotificationsResult { /** * @since 0.2.2 */ notifications: Notification[];}RemoveDeliveredNotificationsOptions
Bagian berjudul āRemoveDeliveredNotificationsOptionsāexport interface RemoveDeliveredNotificationsOptions { /** * @since 0.4.0 */ notifications: Notification[];}SubscribeToTopicOptions
Bagian berjudul āSubscribeToTopicOptionsāexport interface SubscribeToTopicOptions { /** * The name of the topic to subscribe. * * @since 0.2.2 */ topic: string;}UnsubscribeFromTopicOptions
Bagian berjudul āUnsubscribeFromTopicOptionsāexport interface UnsubscribeFromTopicOptions { /** * The name of the topic to unsubscribe from. * * @since 0.2.2 */ topic: string;}CreateChannelOptions
Bagian berjudul āCreateChannelOptionsāexport type CreateChannelOptions = Channel;DeleteChannelOptions
Bagian berjudul āDeleteChannelOptionsāexport interface DeleteChannelOptions { /** * The channel identifier. * * @since 1.4.0 */ id: string;}ListChannelsResult
Bagian berjudul āListChannelsResultāexport interface ListChannelsResult { channels: Channel[];}TokenReceivedListener
Bagian berjudul āTokenReceivedListenerāPanggilan kembali untuk menerima event token diterima.
export type TokenReceivedListener = (event: TokenReceivedEvent) => void;Sumber Kebenaran
Judul Bagian āSumber KebenaranāHalaman ini dibuat dari pluginās src/definitions.tsRe-run sinkronisasi ketika publik API berubah di atas