Zum Hauptinhalt springen
@capgo/capacitor-Benachrichtigungen Geräte-APIs Offene Quelle

Benachrichtigungen Capacitor-Plugin

Benachrichtigungen senden Sie native iOS- und Android-Benachrichtigungen mit Benutzerlookup, Badges, Statistiken und Stille-Update-Überprüfungen mit Capgo.

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

Wie man Benachrichtigungen in Capacitor verwendet

Verwende @capgo/capacitor-Benachrichtigungen

Send native iOS- und Android-Benachrichtigungen von Capgo mit Benutzerlookup, Badges, Vordergrund-/Offen-Tracking, Hintergrundrückruf und stille Capgo Live-Update-Überprüfungen.

Das Plugin ist für den Capgo-Benachrichtigungs-Pipeline erstellt. Capgo speichert Plattformzertifikatsmetadata und Kampagnensteuerungsdaten in Postgres, während aktive Gerätestatus und Lieferungsereignisse in Cloudflare Analytics Engine geschrieben werden.

Installieren

Use the Capgo CLI for a guided setup:

npx @capgo/cli@latest notifications setup com.example.app

Manueller Installationsprozess:

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',
})

Ein registrierter Benutzer anmelden

Mint identityProof von Ihrem Backend mit POST /notifications/recipients/proofund registrieren Sie das Gerät nach Ihrem eigenen Login erfolgreich ist.

await CapgoNotifications.register({
  externalId: 'customer-user-123',
  identityProof,
  tags: ['paid'],
  attributes: { plan: 'team' },
  consent: true,
})

Für Ereignisse lauschen

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-Einrichtung

Aktivieren Benachrichtigungen über Push und Hintergrundmodi > Remotebenachrichtigungen in Xcode.

Remotebenachrichtigungen 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-Einrichtung

Ausführen npx cap sync androidKonfigurieren Sie die Android-Plattformkredite in Capgo, stellen Sie auf Android 13+ die Benachrichtigungsrechte an und testen Sie auf einem Gerät oder einem Emulator mit Google Play-Diensten.

Überprüfungscheckliste

  • Ausführen npx @capgo/cli@latest notifications setup com.example.app aus dem Ordner, der das capacitor.config.*.
  • Suchen Sie den Empfänger in Capgo nach externer Kunden-ID.
  • Bestätigen Sie, dass das Gerät die Plattform android oder ios und die Zustimmung ist erteilt.
  • Hinzufügen Sie temporäre Listener für registrationChanged, notificationReceived, notificationOpened, und backgroundNotification.
  • Senden Sie einen Testbenachrichtigung von der Dashboard.
  • Überprüfe Statistiken für angesammelte, gesendete, empfangene und geöffnete Ereignisse.
  • Für stille Aktualisierungsprüfungen, überprüfen Sie @capgo/capacitor-updater ist installiert und autoUpdater ist aktiviert.

Vollständige Referenz

Mit @capgo/capacitor-notifications weitermachen

Wenn Sie @__CAPGO_KEEP_0__/__CAPGO_KEEP_1__-notifications verwenden Verwenden Sie @capgo/capacitor-notifications um native Push-Messaging zu planen, verbinden Sie es mit @capgo/capacitor-Benachrichtigungen für die Implementierungsdetails, Debugging @__CAPGO_KEEP_0__/__CAPGO_KEEP_1__-updater @capgo/capacitor-Updater für stille Aktualisierungsprüfungen und Capgo Plugin-Verzeichnis für andere native Plugins.

FAQ

Häufig gestellte Fragen

Wie installiere ich die Benachrichtigungs-Plugin in einer Capacitor-App?

Run "bun add @capgo/capacitor-notifications" (or "npm install @capgo/capacitor-notifications"), then run "bunx cap sync" so the iOS and Android projects pick up the native code. Import it from "@capgo/capacitor-notifications" in your app code.

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

Yes. Notifications is a Capacitor package, so it works with any web framework that runs inside Capacitor, including Ionic, React, Vue, Angular, Svelte and plain JavaScript.

Welche Capacitor Version unterstützt @capgo/capacitor-Benachrichtigungen?

Capgo plugins follow Capacitor's major version: use the plugin major version that matches your Capacitor major version (for example plugin v8 with Capacitor 8). The compatibility table in the GitHub README lists the maintained versions.

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

Yes. The source code is public on GitHub at https://github.com/Cap-go/capgo/tree/main/packages/capacitor-notifications/ and the package is free to install from npm. Bug reports and pull requests are welcome.

Kann ich code mit Benachrichtigungen aktualisieren, ohne eine App-Store-Bewertung abzuwarten?

Die Installation oder Aktualisierung des Plugins ändert die native code, daher ist eine neue Build des Stores erforderlich. Anschließend können JavaScript-, HTML- und CSS-Änderungen, die auf das Plugin verweisen, sofort mit Capgo Live-Updates verschickt werden.

Benachrichtigungen ohne Wartezeit auf App-Überprüfung aktualisieren

Einmal der Plugin ist in Ihrem Store Build, Capgo leiten Live Updates Ihre JavaScript, HTML und CSS Änderungen in Minuten an die Benutzer weiter.

Start mit Capgo