I am using react-native-firebase with messaging to deliver notifications to my app with cloud functions, with admin.messaging().send(message), very similar to here: https://medium.com/the-modern-development-stack/react-native-push-notifications-with-firebase-cloud-functions-74b832d45386 .
I receive notifications when the app is in the background. Right now I am sending a text in the body of the notification, like 'a new location has been added to the map'. I want to be able to add some sort of deep link, so that when I swipe View on the notification (on iOS for example), it will take me to a specific screen inside the app. How do I pass data from the notification to the app?
I am using react-native-navigation in the app. I can only find code about deep links from inside the app (https://wix.github.io/react-native-navigation/#/deep-links?id=deep-links).
My solution was to use add what information I need in the data object of the notification message object:
in functions/index.js:
and process as follows in the app for navigation:
I think you don't need to use deep links nor dynamic links but just use Firebase/Notifications properly. If I were you I would add the following logic in the
componentDidMount
method of your parent container:You can find the documentation here: https://rnfirebase.io/docs/v4.3.x/notifications/receiving-notifications
I think you are fine with the "how firebase notification work"... cause of this, here is only an description of the Logic how you can Deeplinking into your App.
If you send a notification, add a data-field. Let's say your app has a Tab-Navigator and the sections "News","Service" and "Review". In your Push-Notification - Datafield (let's name it "jumpToScreen" you define your value:
I assume you still have the Handling to recieve Notifications from Firebase implemented. So create an /lib/MessageHandler.js Class and put your business-logic inside.
In your index.js you can connect it like this:
I hope this give you an Idea how to implement it for your needs.