Linking.canOpenURL cannot tell if the URL is invalid

I am with RN 0.29 RC on iOS
The Linking.canOpenURL returns false even if Linking.openURL(url) does work. I guess this happens because at the first time the user attempts to open the url and then a popup will be shown to ask user’s permission and Linking.canOpenURL will returns false. Although this may be logically correct as it is a fact that user cannot open the url if the permission has not been granted, I cannot tell if this is due to invalid URL (i.e. the user has not installed the specific app that has the scheme and I want to remind the user to install or redirect to app store) or permission problem in this case. My code is like this:

var url = 'myscheme://';
        Linking.canOpenURL(url).then(supported => {
            if (!supported) {
                alert('Cannot open!')
            } else {
                return Linking.openURL(url);
            }
        }).catch(err => console.error('An error occurred', err));

Author: Fantashit

3 thoughts on “Linking.canOpenURL cannot tell if the URL is invalid

Comments are closed.

Linking.canOpenURL cannot tell if the URL is invalid

I am with RN 0.29 RC on iOS
The Linking.canOpenURL returns false even if Linking.openURL(url) does work. I guess this happens because at the first time the user attempts to open the url and then a popup will be shown to ask user’s permission and Linking.canOpenURL will returns false. Although this may be logically correct as it is a fact that user cannot open the url if the permission has not been granted, I cannot tell if this is due to invalid URL (i.e. the user has not installed the specific app that has the scheme and I want to remind the user to install or redirect to app store) or permission problem in this case. My code is like this:

var url = 'myscheme://';
        Linking.canOpenURL(url).then(supported => {
            if (!supported) {
                alert('Cannot open!')
            } else {
                return Linking.openURL(url);
            }
        }).catch(err => console.error('An error occurred', err));

Author: Fantashit

1 thought on “Linking.canOpenURL cannot tell if the URL is invalid

Comments are closed.