Mayoul
Mayoul

Reputation: 626

*React-Native* | Linking => canOpenURL(url) with unknown URL?

I have this piece of code:

Linking.canOpenURL(url)
                    .then((supported) => {
                        if (!supported) {
                            console.log("Can't handle url: " + url);
                            return false;
                        } else {
                            return Linking.openURL(url);
                        }
                    })
                    .catch((err) => console.error('An error occurred', err));

I read in the documentation:

As of iOS 9, your app needs to provide the LSApplicationQueriesSchemes key inside Info.plist or canOpenURL will always return false.

Therefore it is necessary to specify the necessary schemes to manage in info.plist. The problem is that I do not know the URL desired by the user. The user action that calls this Linking.canOpenURL method on my code is here becaus, most of the time, another app opens when you ask this action on my app.

I just want to do :

The user call the action and desire to open an app installed on his phone. I receive a scheme and I need to check if the user indeed have the app installed on his phone to open it.

Does he have the app installed on his phone ? (canOpenURL()) but it could be any scheme Google, Twitter, Instagram, Banking app, that's why I don't know the scheme, there's too much to add in the Info.plist.

If he have the app on his phone, just open it for god sake ahah !

Any ideas ?

Upvotes: 1

Views: 3474

Answers (1)

darkknight
darkknight

Reputation: 372

React Native linking does not need to know the app scheme. All you need to do is find the deep link from the app you want to open and pass that as a url to the Linking component. If the app is installed, it will the link will automatically open in the app.

For example, to open an instagram link directly within the app, you need to call this url instagram://user?username=nike and the app will automatically open if installed.

Upvotes: -1

Related Questions