Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

React Native Linking.canOpenURL() with WhatsApp call

I'm trying to create a link to start a conversation on whatsapp from my react native app, but the method Linking.canOpenURL() is allways retuning false...

My code is the following:

const url = `whatsapp://send?phone=${celNumber}`;
Linking.canOpenURL(url).then(supported => {
    if (supported) {
        Linking.openURL(url);
    } else {
        Alert.alert(
            'Alert',
            'WhatsApp is not installed',
        )
    }
});

If I try to put some other url like tel:${celNumber} it returns true, so I think there is some problem with whatsapp url and canOpenURL(), since the whatsapp url works with the method Linking.openURL()...

like image 972
Marcelo Tardelli Magalhães Avatar asked Mar 10 '18 15:03

Marcelo Tardelli Magalhães


1 Answers

I quess you are using iOS? Then you have to declared the URL’s scheme 'whatsapp' in your Info.plist file LSApplicationQueriesSchemes.

iOS9: canOpenURL returning false for WhatApp's url scheme

https://developer.apple.com/documentation/uikit/uiapplication/1622952-canopenurl

like image 84
SinunHenkka Avatar answered Nov 08 '22 09:11

SinunHenkka