Tokens de Notification (NotificationTokenApi)
Le module NotificationTokenApi permet de gérer les tokens de notification push des clients pour envoyer des notifications sur leurs appareils.
Accès : client.notificationToken
Méthodes
set
Enregistre ou met à jour un token de notification pour un client.
Exemple
final response = await client.notificationToken.set(
SetNotificationTokenParams(
appId: 'app_id',
apiKey: 'user_api_key',
customerId: 'cust_123',
token: 'fcm_token_abc123...',
platform: NotificationPlatform.android,
deviceId: 'device_unique_id',
deviceName: 'Samsung Galaxy S21',
),
);
print('Token enregistré: ${response.data.id}');Si le token existe déjà, il sera mis à jour avec les nouvelles informations d’appareil.
remove
Supprime un token de notification spécifique (déconnexion d’un appareil).
Exemple
final response = await client.notificationToken.remove(
RemoveNotificationTokenParams(
appId: 'app_id',
apiKey: 'user_api_key',
customerId: 'cust_123',
token: 'fcm_token_abc123...',
),
);
if (response.data.removed) {
print('Token supprimé - Appareil déconnecté');
}removeAll
Supprime tous les tokens d’un client (déconnexion de tous les appareils).
Exemple
final response = await client.notificationToken.removeAll(
RemoveAllNotificationTokensParams(
appId: 'app_id',
apiKey: 'user_api_key',
customerId: 'cust_123',
),
);
print('${response.data.removedCount} appareil(s) déconnecté(s)');Utilisez cette méthode avec précaution. Elle déconnecte le client de tous ses appareils.
list
Liste tous les tokens de notification d’un client.
Exemple
final response = await client.notificationToken.list(
ListNotificationTokensParams(
appId: 'app_id',
apiKey: 'user_api_key',
customerId: 'cust_123',
),
);
// Afficher les appareils connectés
for (final token in response.data) {
print('${token.deviceName ?? "Appareil inconnu"} (${token.platform.name})');
}Plateformes supportées
| Enum | Valeur JSON | Description |
|---|---|---|
NotificationPlatform.ios | IOS | Apple Push Notification service (APNs) |
NotificationPlatform.android | ANDROID | Firebase Cloud Messaging (FCM) |
NotificationPlatform.web | WEB | Web Push Notifications |
Gestion des erreurs
| Code erreur | Description |
|---|---|
customer-not-found | Le client n’existe pas |
not-authorized | La clé API n’a pas les droits nécessaires |
invalid-request | Token ou plateforme invalide |
Last updated on