Anleitung
Notifications in Capacitor nutzen
@capgo/capacitor-notifications verwenden
Sende native iOS- und Android-Push-Notifications mit Capgo – inklusive User-Lookup, Badges, Foreground-/Open-Tracking, Background-Callbacks und silent Capgo Live-Update-Checks.
Das Plugin ist für die Capgo Notification-Pipeline gebaut. Capgo speichert Metadaten zu Plattform-Credentials und Kampagnen-Steuerdaten in Postgres, während aktiver Device-Status und Delivery-Events in die Cloudflare Analytics Engine geschrieben werden.
Installieren
Nutze Capgo CLI für ein geführtes Setup:
npx @capgo/cli@latest notifications setup com.example.app
Manuelle Installation:
npm install @capgo/capacitor-notifications @capgo/capacitor-updater
npx cap sync
Konfigurieren
import { CapgoNotifications } from '@capgo/capacitor-notifications'
await CapgoNotifications.configure({
appId: 'com.example.app',
autoUpdater: true,
updateInstallMode: 'next',
})
Einen signierten User registrieren
Mint identityProof von deinem Backend mit POST /notifications/recipients/proof, dann registriere das Gerät, nachdem dein eigener Login erfolgreich war.
await CapgoNotifications.register({
externalId: 'customer-user-123',
identityProof,
tags: ['paid'],
attributes: { plan: 'team' },
consent: true,
})
Auf Events hören
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()
}
})
iOS-Setup
Aktivieren Push-Benachrichtigungen und Background Modes > Remote notifications in Xcode.
Remote-Benachrichtigungen weiterleiten von 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)
}
Android-Setup
Ausführen npx cap sync android, konfiguriere die Android-Plattform-Credentials in Capgo, fordere die Benachrichtigungsberechtigung ab Android 13+ an und teste auf einem Gerät oder Emulator mit Google Play Services.
Debugging-Checkliste
- Ausführen
npx @capgo/cli@latest notifications setup com.example.appaus dem Ordner, der enthältcapacitor.config.*. - Suche den Empfänger in Capgo über die externe Kunden-ID.
- Bestätige, dass das Gerät die Plattform
androidoderiosund die Berechtigung erteilt ist. - Temporäre Listener hinzufügen:
registrationChanged,notificationReceived,notificationOpened, undbackgroundNotification. - Sende eine Testbenachrichtigung über das Dashboard.
- Prüfe die Statistiken für Events mit Status queued, sent, received und opened.
- Bei Silent-Update-Checks prüfen:
@capgo/capacitor-updaterist installiert undautoUpdaterist aktiviert.
Vollständige Referenz
- Docs: /docs/plugins/notifications/
- Debugging: /docs/plugins/notifications/debugging/
- Quelle: https://github.com/Cap-go/capgo/tree/main/packages/capacitor-notifications/
Weiterlesen unter Verwendung von @capgo/capacitor-notifications
Wenn du es nutzt @capgo/capacitor-notifications verwenden um native Push-Messaging zu planen, verbinde es mit @capgo/capacitor-notifications für Details zur Implementierung, Debugging zur Fehlerbehebung, @capgo/capacitor-updater für Silent Update Checks, und Capgo Plugin-Verzeichnis für andere native Plugins.