From 1beb9a99c26722c89793060af1cefb4e3a5e6cd6 Mon Sep 17 00:00:00 2001 From: Elias Nahum Date: Tue, 29 Oct 2024 08:18:51 +0800 Subject: [PATCH] Add logs when notification device tokens is registered or fails to do so (#8282) --- app/init/push_notifications.ts | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/app/init/push_notifications.ts b/app/init/push_notifications.ts index 8de4176d0..1c5eaf8b5 100644 --- a/app/init/push_notifications.ts +++ b/app/init/push_notifications.ts @@ -12,6 +12,7 @@ import { Notifications, type NotificationTextInput, type Registered, + type RegistrationError, } from 'react-native-notifications'; import {requestNotifications} from 'react-native-permissions'; @@ -45,6 +46,8 @@ class PushNotifications { Notifications.events().registerRemoteNotificationsRegistered(this.onRemoteNotificationsRegistered), Notifications.events().registerNotificationReceivedBackground(this.onNotificationReceivedBackground), Notifications.events().registerNotificationReceivedForeground(this.onNotificationReceivedForeground), + Notifications.events().registerRemoteNotificationsRegistrationFailed(this.NotificationsRegistrationFailed), + Notifications.events().registerRemoteNotificationsRegistrationDenied(this.onRemoteNotificationsRegistrationDenied), ]; if (register) { @@ -276,7 +279,9 @@ class PushNotifications { prefix = Device.PUSH_NOTIFY_ANDROID_REACT_NATIVE; } - storeDeviceToken(`${prefix}-v2:${deviceToken}`); + const token = `${prefix}-v2:${deviceToken}`; + storeDeviceToken(token); + logDebug('Notification token registered', token); // Store the device token in the default database this.requestNotificationReplyPermissions(); @@ -284,6 +289,14 @@ class PushNotifications { return null; }; + onRemoteNotificationsRegistrationDenied = () => { + logDebug('Notification registration denied'); + }; + + NotificationsRegistrationFailed = (event: RegistrationError) => { + logDebug('Notification registration failed', event); + }; + removeChannelNotifications = async (serverUrl: string, channelId: string) => { RNUtils.removeChannelNotifications(serverUrl, channelId); };