Guide
Utiliser Notifications dans Capacitor
Utiliser @capgo/capacitor-notifications
Envoyez des notifications push natives iOS et Android depuis Capgo avec recherche d’utilisateurs, badges, suivi au premier plan/à l’ouverture, callbacks en arrière-plan et vérifications silencieuses de live-update Capgo.
Le plugin est conçu pour le pipeline de notifications de Capgo. Capgo stocke les métadonnées des identifiants de plateforme et les données de contrôle des campagnes dans Postgres, tandis que l’état des appareils actifs et les événements de livraison sont écrits dans Cloudflare Analytics Engine.
Installer
Utilisez Capgo CLI pour une configuration guidée :
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',
})
Enregistrer un utilisateur authentifié
Générer identityProof depuis votre backend avec POST /notifications/recipients/proof, puis enregistrez l'appareil une fois votre propre connexion réussie.
await CapgoNotifications.register({
externalId: 'customer-user-123',
identityProof,
tags: ['paid'],
attributes: { plan: 'team' },
consent: true,
})
Écouter 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 en arrière-plan > Notifications distantes dans Xcode.
Transférez les notifications distantes 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écutez npx cap sync android, configurez les identifiants de la plateforme Android dans Capgo, demandez l'autorisation de notification sur Android 13+ et testez sur un appareil ou un émulateur avec les services Google Play.
Checklist de débogage
- Exécutez
npx @capgo/cli@latest notifications setup com.example.appdepuis le dossier qui contientcapacitor.config.*. - Recherchez le destinataire dans Capgo par ID client externe.
- Confirmez que l'appareil dispose de la plateforme
androidouioset que l’autorisation est accordée. - Ajouter des listeners temporaires pour
registrationChanged,notificationReceived,notificationOpened, etbackgroundNotification. - Envoyer une notification de test depuis le dashboard.
- Vérifier les statistiques des événements en file d’attente, envoyés, reçus et ouverts.
- Pour les vérifications de mise à jour silencieuses, vérifiez
@capgo/capacitor-updaterest installé et queautoUpdaterest activé.
Référence complète
- Docs : /docs/plugins/notifications/
- Débogage : /docs/plugins/notifications/debugging/
- Source : https://github.com/Cap-go/capgo/tree/main/packages/capacitor-notifications/
Continuer avec l'utilisation de @capgo/capacitor-notifications
Si vous utilisez Utiliser @capgo/capacitor-notifications pour planifier les notifications push natives, connectez-l’à @capgo/capacitor-notifications pour les détails d'implémentation, Débogage pour le dépannage, @capgo/capacitor-updater pour les vérifications silencieuses de mise à jour, et Capgo Répertoire des plugins pour les autres plugins natifs.