Linking in react native can open just one app

Your issue is related to the content of the url, twitter:// means nothing for the Android Twitter app, so it will not open.

For example, the following code should work:

   Linking.openURL('twitter://timeline')

or

    Linking.openURL('instagram://user?username=apple')

You have to find the rights url schemes (documentations are not very clear about it) that may be different between iOS and Android.

  • Twitter: How can I open a Twitter tweet using the native Twitter app on iOS?

  • Instagram: https://www.instagram.com/developer/mobile-sharing/iphone-hooks/ (all do not work on Android)

  • misc: https://pureoxygenlabs.com/10-app-url-schemes-for-marketers/


I have used only url and it's working both iOS and android

Linking.openURL('https://www.facebook.com/');

Your code looks pretty solid, here's an example of how I open twitter in my app.

const twitterUrlScheme = `twitter://user?screen_name=${twitterUsername}`;

Linking.canOpenURL(twitterUrlScheme)
    .then((supported) =>
        Linking.openURL(
            supported
                ? twitterUrlScheme
                : `https://www.twitter.com/${twitterUsername}`
            )
        )
        .catch((err) => console.error('An error occurred', err));

I think perhaps your issue might be the return Linking.openUrl, I'm not sure you need the return in that statement. Does it work if you remove the return? Otherwise, it might help to move your Alert outside of the then-block from canOpenUrl.


You have to find the rights URL schemes. Have look at my code

Instagram

Linking.openURL('instagram://user?username=apple')
  .catch(() => {
    Linking.openURL('https://www.instagram.com/apple');
  })

Twitter

Linking.openURL('twitter://user?screen_name=apple')
  .catch(() => {
    Linking.openURL('https://www.twitter.com/apple');
  })

Facebook

Linking.openURL('fb://page/PAGE_ID');
Linking.openURL('http://instagram.com/_u/USER_NAME');
Linking.openURL('http://instagram.com/_p/PICTURE');

Tags:

React Native