Quirks with push notifications triggering deep links

Please provide the following:

  1. SDK Version: 40.0.1
  2. Platforms(Android/iOS/web/all): all

I’d like to handle push notifications with React Navigation. I’ve followed the demo code here.

This is my code

import * as Linking from 'expo-linking';
import * as Notifications from 'expo-notifications';

Notifications.setNotificationHandler({
  handleNotification: async () => ({
    shouldShowAlert: true,
    shouldPlaySound: true,
    shouldSetBadge: true
  })
});

export default {
  prefixes: [Linking.makeUrl('/'), 'https://createdeepconnections.com'],
  subscribe(listener) {
    const onReceiveURL = ({ url }: { url: string }) => listener(url);

    // Listen to incoming links from deep linking
    Linking.addEventListener('url', onReceiveURL);

    // Listen to expo push notifications
    const subscription = Notifications.addNotificationResponseReceivedListener(
      response => {
        const url = response.notification.request.content.data.url;

        listener(Linking.makeUrl(url));
      }
    );

    return () => {
      // Clean up the event listeners
      Linking.removeEventListener('url', onReceiveURL);
      subscription.remove();
    };
  },
  config: {
    screens: {
      Root: {
        screens: {
          Home: {
            initialRouteName: 'HomeScreen',
            screens: {
              QuestionScreen: 'question/:questionSetId/:questionId'
            }
          }
        }
      }
    }
  }
};

When the app is open at the HomeScreen, and when a push notification comes through with the deep link URL in the data, and I tap it, it correctly navigates to the correct screen.

However, if the app is closed, pushing the push notification will open the app but not navigate to the screen. Also I noticed if I’m on another screen, and a push notification comes through, nothing happens when I tap the push notification.

Am I missing something, or is this a bug?

I thought the addNotificationResponseReceivedListener listener is fired whether the app is open or not? “This listener is fired whenever a user taps on or interacts with a notification (works when app is foregrounded, backgrounded, or killed). This listener is especially useful for routing users to a particular screen after they tap on a particular notification.”

2 Likes

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.