infobip / mobile-messaging-react-native-plugin

Mobile Messaging SDK plugin for React Native projects
24 stars 4 forks source link

Deep Link Handling in Notifications #71

Open moustafadevrn opened 1 month ago

moustafadevrn commented 1 month ago

When you receive notifications containing deep links and the app is not open, your React Native app fails to detect the deep link URL using the Linking.getInitialURL() method. As a result, the app does not navigate to the appropriate page specified in the deep link URL.

but manually triggering the deep link using the following adb shell command successfully detects the deep link URL:

adb shell am start -a android.intent.action.VIEW -d "com.infobip.mobilemessaging://deeplink/TestDeeplinkingScreen/TestDeeplinkingScreen2" com.example

and Here is the code snippet you are using to handle the initial deep link URL:

function handleInitialDeeplinkUrl() { Linking.getInitialURL() .then(initialUrl => { if (!initialUrl) { return; } console.log(initialUrl); }) .catch(error => { console.log('Initial URL is not provided'); }); }

React.useEffect(() => { handleInitialDeeplinkUrl(); }, []);

Steps to Reproduce:

  1. Attach a deep link to a push notification.
  2. Send the notification to an Android device.
  3. Observe that the app does not navigate to the expected page.

Expected Outcome:

The app should detect the URL and navigate to the expected page.

Actual Outcome: The app does not detect the URL and therefore does not navigate to the expected page.

fortesdev commented 1 month ago

Hi, This is potentially a React Native problem: https://github.com/facebook/react-native/issues/25675

moustafadevrn commented 1 month ago

@fortesdev we appreciate your feedback on the deep linking part. However, we believe this is not a React Native issue as you suggest. We are currently using React Native OneSignal, and we have successfully attached a launch link in both iOS and Android environments in production. This approach has been effective in redirecting the user to the specified page, so we are confident that the deep linking is working as expected within the React Native ecosystem.

We kindly request you to re-evaluate the issue or provide any additional guidance on how we can troubleshoot this specific deep linking challenge. We value your support and insights.

fortesdev commented 1 month ago

Apologies and reopening the issue, we will investigate this further.

alboldy-ib commented 1 month ago

Hello there, Indeed, our current implementation does not utilise Linking properly, yet it relies on navigation like in example here - https://github.com/infobip/mobile-messaging-react-native-plugin/wiki/How-to-use-%22deeplink%22-to-land-user-to-a-particular-app-page%3F#implement-deeplinks-handling-method

Feel free to test suggested implementation and let us know upon the results.

moustafadevrn commented 1 month ago

@alboldy-ib Thank you for the information and the suggested implementation for handling deep links.

Indeed, I use navigation in my app to detect the initial URL via Linking.getInitialURL(). However, there seems to be an issue as the URL detection does not occur, and the URL value is null when I press on a notification that includes a link.

Additionally, I have noticed inconsistencies with the notificationTapped library event. While it triggers as expected when the app is open and I press on the notification on Android devices, it does not trigger when the app is closed and I press on the notification.

These challenges have made it difficult to handle deep links effectively within the app. I would appreciate any further guidance or insights you can provide on resolving these issues.

Thank you for your assistance.