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 en arrière-plan/ouverture, rappels en arrière-plan et vérifications silencieuses de mise à jour en direct Capgo.
Le plugin est conçu pour le pipeline de notification Capgo. Capgo stocke les métadonnées de la clé de 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
Cette package est actuellement en prévue privée. Capgo doit activer l'accès au package pour votre compte npm avant que l'installation fonctionne.
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',
})
Enregistrer un utilisateur signé
Mint identityProof à partir de votre backend avec POST /notifications/recipients/proofEnsuite, enregistrez le dispositif après que votre connexion réussit.
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 d'arrière-plan > Notifications à distance en 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 d'Android
Exécutez npx cap sync androidConfigurez les informations d'identification de la 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écutez
npx @capgo/cli@latest notifications setup com.example.appà partir du dossier qui contientcapacitor.config.*. - Recherchez le destinataire dans Capgo par l'ID client externe.
- Vérifiez que l'appareil a la plateforme
androidouioset la permission est accordée. - Ajoutez des écouteurs temporaires pour
registrationChanged,notificationReceived,notificationOpenedetbackgroundNotification. - 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-updaterest installé etautoUpdaterest activé.
Référence complète
- Documentation : /docs/plugins/notifications/
- Débogage : /docs/plugins/notifications/debugging/
- Source : https://github.com/Cap-go/capgo/tree/main/packages/capacitor-notifications/
Continuez à partir de l'utilisation de @capgo/capacitor-notifications
Si vous utilisez Utilisation de @capgo/capacitor-notifications pour planifier la messagerie de poussée native, connectez-le avec @capgo/capacitor-notifications pour les détails d'implémentation, Débogage pour le dépannage, @capgo/capacitor-updater pour les vérifications de mise à jour silencieuses, et Répertoire de plugins Capgo pour d'autres plugins natives.