Zum Hauptinhalt springen
@capgo/capacitor-notifications Device-APIs Open Source

Benachrichtigungen Capacitor Plugin

Sende native Push-Benachrichtigungen für iOS und Android mit Capgo – inklusive User-Lookup, Badges, Statistiken und Silent-Update-Checks.

Installieren

bun add @capgo/capacitor-notifications bunx cap sync
npm, pnpm oder yarn
  • npm install @capgo/capacitor-notifications
  • pnpm add @capgo/capacitor-notifications
  • yarn add @capgo/capacitor-notifications

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.app aus dem Ordner, der enthält capacitor.config.*.
  • Suche den Empfänger in Capgo über die externe Kunden-ID.
  • Bestätige, dass das Gerät die Plattform android oder ios und die Berechtigung erteilt ist.
  • Temporäre Listener hinzufügen: registrationChanged, notificationReceived, notificationOpened, und backgroundNotification.
  • 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-updater ist installiert und autoUpdater ist aktiviert.

Vollständige Referenz

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.

FAQ

Notifications Plugin FAQ

Wie installiere ich das Notifications Plugin in einer Capacitor App?

Führe "bun add @capgo/capacitor-notifications" (oder "npm install @capgo/capacitor-notifications") aus und danach "bunx cap sync", damit die iOS- und Android-Projekte die nativen code übernehmen. Importiere es in deiner App code aus "@capgo/capacitor-notifications".

Funktioniert @capgo/capacitor-notifications mit React, Vue und Angular?

Ja. Notifications ist ein Capacitor Package und funktioniert daher mit jedem Web-Framework, das innerhalb von Capacitor läuft, einschließlich Ionic, React, Vue, Angular, Svelte und reinem JavaScript.

Welche Capacitor Version wird von @capgo/capacitor-notifications unterstützt?

Capgo Plugins folgen der Major-Version von Capacitor: Nutze die Plugin-Major-Version, die zu deiner Capacitor Major-Version passt (z. B. Plugin v8 bei Capacitor 8). Die Kompatibilitätstabelle im GitHub README listet die gepflegten Versionen auf.

Ist @capgo/capacitor-notifications kostenlos und Open Source?

Ja. Der code Code ist öffentlich auf GitHub unter https://github.com/Cap-go/capgo/tree/main/packages/capacitor-notifications/ einsehbar und das Package kann kostenlos über npm installiert werden. Bug-Reports und Pull Requests sind willkommen.

Kann ich code mit Notifications aktualisieren, ohne ein App Store Review abzuwarten?

Die Installation oder ein Upgrade des Plugins ändert den nativen code, weshalb ein neuer Store-Build nötig ist. Danach können JavaScript-, HTML- und CSS-Änderungen, die das Plugin aufrufen, sofort per Capgo Live Updates ausgeliefert werden.

Notifications-Änderungen ausrollen, ohne auf den App-Review zu warten

Sobald das Plugin in deinem Store-Build ist, bringt Capgo mit Live-Updates deine JavaScript-, HTML- und CSS-Änderungen in Minuten zu den Nutzern.

Starte mit Capgo