Linking.openURL not working for expo go app in development on ios 14

Please provide the following:

  1. SDK Version: 41.0.0
  2. Platforms(Android/iOS/web/all): ios
  3. Add the appropriate “Tag” based on what Expo library you have a question on.

I’m using the Linking package to open a local link within an expo app when a notification is pressed. It works fine on android and older iphones (7,8), but I’m having trouble on ios 14 on an iphone 12 pro. It redirects to the home page when clicked. The user is running the app through Expo Go via a tunnel connection. See the code below, thanks in advance:

useEffect(() => {
const backgroundSubscription =
Notifications.addNotificationResponseReceivedListener((response) => {
console.log(“in background”, response);
let url =
prefix +
“postingDescription/” +
response.notification.request.content.data.postingID;

    Linking.openURL(url);
  })

});

Hey @rowellscott, the code snippet refers to variables that aren’t present here. Can you provide a complete, runnable repro case of this so we can confidently test it on our end?

Cheers,
Adam

Hey Adam,
I was able to get around the above issue by using the linking prop on the React Navigation Navigation Container with the code below. I’m still trying to figure out the best way to do the linking if the app isn’t running and I hit a notification. It navigates to the home page instead of the linked page. Appreciate any advice you might have on how to do this.

 <NavigationContainer
  fallback={<Text>Loading...</Text>}
    linking={{
      prefixes: [prefix],
      config: {
        screens: {
          Login: "login",
          Home: "home",
          PostingDescription: "postingDescription/:id",
        },
      },
      subscribe(listener) {
        const onReceiveURL = ({ url }: { url: string }) => listener(url);

        // Listen to incoming links from deep linking
        Linking.addEventListener("url", onReceiveURL);
        console.log(url)
        // Listen to expo push notifications
        const subscription = Notifications.addNotificationResponseReceivedListener(response => {
          console.log("notification", response)
          // response.notification.request.content.data.url
          let url = prefix + "postingDescription/" + response.notification.request.content.data.postingID;
          
          console.log("url   ", url)
          // Any custom logic to see whether the URL needs to be handled
          //...
          // Let React Navigation handle the URL
          listener(url);
        });
        return () => {
          // Clean up the event listeners
          Linking.removeEventListener("url", onReceiveURL);
          subscription.remove();
        };
      },
    }}
  >
    <StackNavigator />
  </NavigationContainer>
1 Like

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