Passer à la navigation principale
Retour aux plugins
@capgo/capacitor-notifications
Guide
@capgo/capacitor-notifications

Notifications

Envoyez des notifications push natives iOS et Android à partir de Capgo avec recherche d'utilisateur, badges, statistiques et vérifications de mise à jour silencieuse

Guide

Tutoriel sur les notifications

Utiliser @capgo/capacitor-notifications

Envoyer des notifications push natives iOS et Android à partir de Capgo avec recherche d'utilisateur, badges, suivi de l'ouverture/foreground, rappels de fond et vérifications de mise à jour silencieuses Capgo

Le plugin est conçu pour le pipeline de notification Capgo. Capgo stocke les métadonnées de la plateforme et les données de contrôle de campagne dans Postgres, tandis que l'état actif des appareils et les événements de livraison sont écrits dans l'Cloudflare Analytics Engine

Installer

Utilisez le Capgo CLI pour un setup guidé :

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

Installation manuelle :

npm install @capgo/capacitor-notifications @capgo/capacitor-updater
npx cap sync

Configurer

import { CapgoNotifications } from '@capgo/capacitor-notifications'

await CapgoNotifications.configure({
  appId: 'com.example.app',
  autoUpdater: true,
  updateInstallMode: 'next',
})

Inscription d'un Utilisateur Signé

Mint identityProof à partir de votre serveur avec POST /notifications/recipients/proof, puis inscrivez ensuite le dispositif après que votre propre connexion réussisse.

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

Ecoutez les Événements

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()
  }
})

Configuration iOS

Activer Notifications Push et Modes d'arrière-plan > Notifications à distance dans Xcode.

Transmettez les notifications à distance depuis 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)
}

Configuration Android

Exécuter npx cap sync androidConfigurez les informations de plateforme Android dans Capgo, demandez la permission de notification sur Android 13+ et testez sur un appareil ou un émulateur avec Google Play services.

Liste de vérification de débogage

  • Exécuter npx @capgo/cli@latest notifications setup com.example.app à partir du dossier qui contient capacitor.config.*.
  • Recherchez le destinataire dans Capgo par ID client externe.
  • Confirmez que l'appareil a la plateforme android ou ios context
  • La permission est accordée. registrationChanged, notificationReceived, notificationOpenedAjoutez des écouteurs temporaires pour backgroundNotification.
  • Envoyer une notification de test depuis l'interface de dashboard.
  • Vérifier les statistiques pour les événements en attente, envoyés, reçus et ouverts.
  • Pour les vérifications de mise à jour silencieuses, vérifiez que @capgo/capacitor-updater est installé et autoUpdater est activé.

Référence complète

Continuez à partir de l'utilisation de @capgo/capacitor-notifications

Si vous utilisez Utilisez @capgo/capacitor-notifications pour planifier le messagerie de notification native, connectez-l’avec @capgo/capacitor-notifications pour les détails d'implémentation, Débogage pour le dépannage, @capgo/capacitor-updater pour les contrôles de mise à jour silencieuse, et Répertoire de plugins Capgo pour d'autres plugins natives.