Expo Linking back to App

I have been using Expo to develop a react-native app, The functionality I am currently trying to implement is to share a link with friends on platforms such as fb messenger/whatapp or even normal texts and when they click this link it will launch my app.

After extensive research online - I’ve come to a blocker, following expo’s documentation I defined a scheme for my app - when I press share everything works correctly a message is created and I’m able to share content but only as string.

I am using react-natives Share library to share to an app and I’m using Expo to provide me with the link.

Ideally my first goal is to get the app opening using the Expo Link before I explore further into adding more functionality to the link.

Share.share({
    message: "Click Here to View More! " + Expo.Linking.makeUrl() ,
    url: Expo.Linking.makeUrl(),
    title: 'Sufiyaan has invited you to join this activity',
  })
  .then((result) =>{
    console.log(result)
      if(result === 'dismissedAction'){
        return
      }
  })
  .catch((error) => console.log(error))

In the root of my app I have also defined the event handlers: App.js

handleOpenURL(event) {
  if (event.url && event.url.indexOf(scheme + '://') === 0) {
      crossroads.parse(event.url.slice(scheme.length + 3));
  }
}

componentDidMount() {
  let scheme = 'nxet'
  Expo.Linking.getInitialURL()
    .then(url => {
      console.log("App.js getInitialURL Triggered")
      // this.handleOpenURL({ url });
    })
    .catch(error => console.error(error));
  Linking.addEventListener('url', this.handleOpenURL);
}

componentWillUnmount() {
  Linking.removeEventListener('url', this.handleOpenURL);
}

When I share the link to Whatsapp, Facebook Messenger or even just messages or notes it appears as myapplink://, I try to enter this into the browser and instead of asking me to open my app - it does a google search.

Please note I am attempting to have this working on both iOS & Android Device and facing this issue in an Android device.

Is there something I am doing incorrectly?

Any help is much appreciated. Thanks.

Hi! Are you testing this inside Expo Client or inside a standalone app that you created with exp build? makeUrl() will return a different value depending on the context. If you’re using a standalone app, it will return something like myapp://, but if you’re testing in Expo Client, it will look like expo.io/@yourname/yourapp/--/. If you change the value for scheme and you want your standalone app to work correctly, then you need to rebuild the standalone app to be configured for that scheme. Hope that helps!

Hey Ben,

Thanks for the response - so right now I’m testing it a bit everywhere to get a better understanding of how I will be using it - I have defined a scheme in my app.json as I do need this to work in a standalone app - I understand that makeUrl() will make the url based on the environment.

When I run it in the standalone app a url is made properly - when I share this url with a friend lets say on Messenger or WhatsApp - it shows up as “myapp://” (String/piece of text) than an actual url

I’m trying to share some basic content from my app to a friend ( this is my usecase) ideally I’d want them to be able to click the url which opens my app but it seems it doesn’t send it as a url ?

Is there something I’m doing wrong?

The recipient’s device should identify myapp://whatever as a url if they have your app installed. If they don’t, it probably won’t show up as a url.

Okay that makes sense at the moment it doesn’t show up as a url for some reason when I do an exp build:android and run the applcation on my phone, when I go to share it with a friend it shows up as text - I’ve decided to move forward by using branch from the dangerzone in Expo - hopefully this can help me meet my usecase

Thank You for your help :slight_smile:

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