Add logs when notification device tokens is registered or fails to do so (#8282)

This commit is contained in:
Elias Nahum 2024-10-29 08:18:51 +08:00 committed by GitHub
parent c1b66b364b
commit 1beb9a99c2
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -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);
};