From 7b0a037c63a95a940e5e5356cd5e1d6c67275692 Mon Sep 17 00:00:00 2001 From: Francesco De Giorgio Date: Mon, 5 Oct 2026 12:37:27 +0200 Subject: [PATCH] fix(push-notifications): resolve unregister() only after FCM token deletion completes on Android unregister() resolved right after calling deleteToken(), so a register() issued before the deletion finished received the cached token, which FCM invalidated moments later. Resolve from the deleteToken() completion listener and reject if the deletion fails. --- .../pushnotifications/PushNotificationsPlugin.java | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/push-notifications/android/src/main/java/com/capacitorjs/plugins/pushnotifications/PushNotificationsPlugin.java b/push-notifications/android/src/main/java/com/capacitorjs/plugins/pushnotifications/PushNotificationsPlugin.java index 63916663a..cf1cb30d1 100644 --- a/push-notifications/android/src/main/java/com/capacitorjs/plugins/pushnotifications/PushNotificationsPlugin.java +++ b/push-notifications/android/src/main/java/com/capacitorjs/plugins/pushnotifications/PushNotificationsPlugin.java @@ -127,8 +127,16 @@ public void register(PluginCall call) { @PluginMethod public void unregister(PluginCall call) { FirebaseMessaging.getInstance().setAutoInitEnabled(false); - FirebaseMessaging.getInstance().deleteToken(); - call.resolve(); + FirebaseMessaging.getInstance() + .deleteToken() + .addOnCompleteListener((task) -> { + if (!task.isSuccessful()) { + Exception exception = task.getException(); + call.reject(exception != null ? exception.getLocalizedMessage() : "Failed to delete FCM token", exception); + return; + } + call.resolve(); + }); } @PluginMethod