0

I'm using react-native and onesignal to handle notification.

If you press the notification when the app is in the background, i'll catch the 'opened' event, and redirect to the correct route (in the notification metadata)

But when the app is closed, the click on the notification just opens the app, without firing the 'opened' event.

How can i fetch the initial pressed notification metadata ?

Thanks

Abel Chalier
  • 629
  • 6
  • 14

1 Answers1

0

If you are using RNFirebase Cloud Messaging, you can use the proper listener getInitialNotification where you can catch when the notification is opened while the app is closed. Follow that guide Notifications - Handling Interaction for more infos.

Poli97
  • 305
  • 4
  • 18
  • I'm not using firebase but onesignal for notification, it'll still work the same ? – Abel Chalier Feb 16 '21 at 10:32
  • @AbelChalier honestly, I never used onesignal, but all those stuffs works almost the same, so it should have a notification listener too. I gave a quick look at [onesignal mobile push documentation](https://documentation.onesignal.com/docs/react-native-sdk-setup) and if you look at the example at **step 5**, it shows some code with handlers, like `OneSignal.setNotificationOpenedHandler`, I think this is what you are looking for – Poli97 Feb 16 '21 at 15:30