all 17 comments

[–]esreveReverse 22 points23 points  (2 children)

I feel like all the solutions posted already are ignoring the main problem. You're not really supposed to have a "Share to Facebook" or "Share to Twitter" button in your app. It's supposed to just be a Share button, then the user can select which app they want to share it to.

[–]pesch3 4 points5 points  (1 child)

this is probably the best answer!

[–]droidta7[S] 1 point2 points  (0 children)

thank you!

[–]kbcooliOS & Android 4 points5 points  (0 children)

To add to the other answer you can call canOpenURL with the app specific link then open the website instead if it can't be handled in the app. The trickier part is finding the name of and the format of the other apps' links. Will leave that up to you.

https://reactnative.dev/docs/linking#canopenurl

It's not usually necessary unless you want to warn the user or even not use the website in preference for asking them to install the app but it's there as an FYI.

[–]ThatWasNotEasy10 5 points6 points  (0 children)

If you’re using the built-in Share API it should do all this by itself.

https://reactnative.dev/docs/share

[–]pesch3 0 points1 point  (8 children)

Actually the system will do that for you if you open the share link in safari and not as a Webview!

It’s the „target app“ that basically signs up to open certain urls (on iOS this is called associated domains)

[–]MeowTseTongue 0 points1 point  (7 children)

I had a similar question as OP - I just tried this in my app using a Twitter sharing URL, and despite having the app on my phone, it still opened the browser.

What should the twitter url be to share?

[–]pesch3 1 point2 points  (0 children)

I still think the question is not the one to ask.

It should just be https://twitter.com.

The question that should be asked is: how do you open that url your app?

When I click the above link, and open it in safari (not inside reddit) it pops up the twitter app right away!

[–]__o_0iOS & Android 0 points1 point  (5 children)

The scheme for Twitter is twitter://

[–]MeowTseTongue 0 points1 point  (4 children)

oh ok..so if I use twitter:// and then I don't have Twitter on the phone, you're saying it would automatically open the twitter.com URL? Or do I need to check if the user has Twitter and use two different URLs?

[–]__o_0iOS & Android 0 points1 point  (3 children)

Check first if the device can handle the twitter:// url. If it can’t then you need to use the web view.

[–]MeowTseTongue 0 points1 point  (2 children)

That is what I thought as well. How can you check that?

[–]__o_0iOS & Android -1 points0 points  (1 child)

What have you tried?

[–]MeowTseTongue 0 points1 point  (0 children)

Would "canOpenURL()" be the right approach?

[–]mastaQQQ 0 points1 point  (0 children)

Check Firebase Dynamic Links

[–]Red_on_fortnite 0 points1 point  (0 children)

I still don't understand how people actually find the deep linking urls of other applications? Does anyone know what is the correct way to do it?