Skip to content

Commit

Permalink
Add logs when notification device tokens is registered or fails to do so
Browse files Browse the repository at this point in the history
  • Loading branch information
enahum committed Oct 23, 2024
1 parent 8c7c02d commit 5f20a62
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion app/init/push_notifications.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
Notifications,
type NotificationTextInput,
type Registered,
type RegistrationError,
} from 'react-native-notifications';
import {requestNotifications} from 'react-native-permissions';

Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -276,14 +279,24 @@ 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();
}
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);
};
Expand Down

0 comments on commit 5f20a62

Please sign in to comment.