react-native-push-notification icon indicating copy to clipboard operation
react-native-push-notification copied to clipboard

How to handle notification actions clicks on android on background/killed states

Open riad40 opened this issue 5 months ago • 0 comments

Hey guys, basically the situation is i receive a ( data-only ) remote message and then push a local notification and add actions to it, but when it comes to handling em in background and quit state, i click the actions nothing happens here's the code i call on my index.js

PushNotification.configure({
  onNotification: function (notification) {

    const appState = AppState.currentState;

    if (appState !== 'active') {
      if (!notification.userInteraction) {
        PushNotification.localNotification({
          channelId: '// some chennel id',
          title: notification.data.title,
          message: notification.data.message,
          priority: 'high',
          actions: JSON.parse(notification.data.actions).map(
            (item: any) => item.title,
          ),
          smallIcon: 'ic_notification_icon',
          largeIcon: '',
          bigText: '',
          subText: '',
          bigPictureUrl: '',
          userInfo: notification.data,
        });
      } else {
        const actionIdentifier = notification.action;

        if (!actionIdentifier) return;

        switch (actionIdentifier) {
          case 'YES':
            console.log(actionIdentifier);
            break;

          case 'NO':
            console.log(actionIdentifier);
            break;

          case 'CHECK':
            // open the app and navigate to a notifs screen
            break;

          default:
            console.log('No actionIdentifier selected', actionIdentifier);
            break;
        }
      }
    }
  },
});

riad40 avatar Sep 19 '24 17:09 riad40