0

I am using firebase to send push notification to my react native app.

I am able to send notification to my device.

I am using https://fcm.googleapis.com/fcm/send to send notification. Below is the body which I am sending to the api.

{
    "to": "token",
    "notification": {
        "body": "body",
        "title": "title",
        "subtitle": "subtitle"
 
    },
    "data": {
        "gcm.n.link": "myApp://?screenName=TradeDetail"
    }
}

Then I am using Linking to get the url:

Linking.getInitialURL()
  .then((initialUrl) => {
    console.log("initialUrl: ", initialUrl);
  })
  .catch((err) => {
    console.log("Error getting initial URL:", err);
  });

I am getting initial url and able to navigate user to its respective screen.

Problem arises when app is already open, in this case when I click on notification, then nothing happens.

How can I detect url in notification when app is already open and user clicks on it?

1 Answer 1

0

If you are using notifee it provides foreground services that will do the job. Check this Notifee

useEffect(() => {
    const notificationSub = notifee.onForegroundEvent(({ type, detail }) => {
        switch (type) {
            case EventType.DISMISSED:
                console.log('User dismissed notification', detail.notification);
                break;
            case EventType.PRESS:
                console.log('User pressed notification', detail.notification);
                break;
        }
    });
    return notificationSub;
}, [])
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.