Panduan
Cara menggunakan Notifications di Capacitor
Menggunakan @capgo/capacitor-notifications
Kirim push notifications native iOS dan Android dari Capgo dengan user lookup, badge, tracking foreground/open, background callbacks, dan silent Capgo live-update checks.
Plugin ini dibuat untuk pipeline notifikasi Capgo. Capgo menyimpan metadata kredensial platform dan data kontrol kampanye di Postgres, sementara status perangkat aktif dan event pengiriman ditulis ke Cloudflare Analytics Engine.
Instal
Gunakan Capgo CLI untuk setup terpandu:
npx @capgo/cli@latest notifications setup com.example.app
Instalasi manual:
npm install @capgo/capacitor-notifications @capgo/capacitor-updater
npx cap sync
Konfigurasi
import { CapgoNotifications } from '@capgo/capacitor-notifications'
await CapgoNotifications.configure({
appId: 'com.example.app',
autoUpdater: true,
updateInstallMode: 'next',
})
Daftarkan User yang Sudah Login
Mint identityProof dari backend Anda menggunakan POST /notifications/recipients/proof, lalu daftarkan perangkat setelah login Anda berhasil.
await CapgoNotifications.register({
externalId: 'customer-user-123',
identityProof,
tags: ['paid'],
attributes: { plan: 'team' },
consent: true,
})
Dengarkan Event
await CapgoNotifications.addListener('notificationReceived', (notification) => {
console.log('Received', notification)
})
await CapgoNotifications.addListener('notificationOpened', (event) => {
console.log('Opened', event.notification.id)
})
await CapgoNotifications.addListener('backgroundNotification', async (event) => {
try {
console.log('Background payload', event.notification.data)
} finally {
await event.finish()
}
})
Setup iOS
Aktifkan Notifikasi Push dan Background Modes > Remote notifications di Xcode.
Teruskan notifikasi remote dari ios/App/App/AppDelegate.swift:
func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable: Any], fetchCompletionHandler completionHandler: @escaping (UIBackgroundFetchResult) -> Void) {
NotificationCenter.default.post(name: Notification.Name("CapgoNotificationsRemoteNotification"), object: userInfo)
completionHandler(.newData)
}
Setup Android
Jalankan npx cap sync android, konfigurasi kredensial platform Android di Capgo, minta izin notifikasi di Android 13+, dan tes di perangkat atau emulator dengan Google Play services.
Checklist Debugging
- Jalankan
npx @capgo/cli@latest notifications setup com.example.appdari folder yang berisicapacitor.config.*. - Cari penerima di Capgo berdasarkan external customer ID.
- Pastikan perangkat memiliki platform
androidatauiosdan izin sudah diberikan. - Tambahkan listener sementara untuk
registrationChanged,notificationReceived,notificationOpened, danbackgroundNotification. - Kirim notifikasi uji coba dari dashboard.
- Cek statistik untuk event queued, sent, received, dan opened.
- Untuk pengecekan update silent, verifikasi
@capgo/capacitor-updatersudah terinstal danautoUpdatersudah diaktifkan.
Referensi Lengkap
- Dokumentasi: /docs/plugins/notifications/
- Debugging: /docs/plugins/notifications/debugging/
- Sumber: https://github.com/Cap-go/capgo/tree/main/packages/capacitor-notifications/
Lanjutkan dari Menggunakan @capgo/capacitor-notifications
Jika Anda menggunakan Menggunakan @capgo/capacitor-notifications untuk merencanakan native push messaging, hubungkan dengan @capgo/capacitor-notifications untuk detail implementasi, Debugging untuk troubleshooting, @capgo/capacitor-updater untuk silent update checks, dan Direktori Plugin Capgo untuk plugin native lainnya.