Panduan
Cara menggunakan Rich Notifications di Capacitor
Menggunakan @capgo/capacitor-rich-notifications
Notifikasi lokal dengan channel Android, layout progres, tombol aksi, penjadwalan, dan level interupsi iOS.
Instal
bun add @capgo/capacitor-rich-notifications
bunx cap sync
Apa yang Diekspos Plugin Ini
checkPermission- Cek status izin notifikasi lokal.requestPermission- Minta izin notifikasi lokal.createChannel- Buat channel notifikasi Android.createChannelGroup- Buat grup channel Android.deleteChannel- Hapus channel notifikasi Android.display- Tampilkan notifikasi lokal segera.schedule- Jadwalkan notifikasi lokal untuk nanti.cancel- Batalkan satu notifikasi berdasarkan id.cancelAll- Batalkan semua notifikasi yang dikelola plugin ini.getDisplayed- Tampilkan daftar notifikasi yang muncul di shade atau center.getPending- Tampilkan daftar notifikasi terjadwal yang belum muncul.getInitialNotification- Kembalikan notifikasi yang membuka app, jika ada.setBadge- Set jumlah badge ikon aplikasi di iOS.registerActions- Daftarkan kategori aksi yang dapat digunakan ulang.getPluginVersion- Mengembalikan penanda versi implementasi platform.addListener- Dengarkan event press dan dismiss.
Contoh Penggunaan
requestPermission dan display
import { RichNotifications } from '@capgo/capacitor-rich-notifications';
await RichNotifications.requestPermission();
await RichNotifications.createChannel({
id: 'messages',
name: 'Messages',
importance: 'high',
});
await RichNotifications.display({
title: 'Hello',
body: 'Tap to open the app',
channelId: 'messages',
});
schedule
import { RichNotifications } from '@capgo/capacitor-rich-notifications';
await RichNotifications.schedule({
notification: {
id: 'reminder-1',
title: 'Reminder',
body: 'Your appointment starts soon',
channelId: 'messages',
},
trigger: { type: 'timestamp', timestamp: Date.now() + 60_000 },
});
Referensi Lengkap
- GitHub: https://github.com/Cap-go/capacitor-rich-notifications/
- Docs: /docs/plugins/rich-notifications/