使用 WhatsApp 调用 React Native Linking.canOpenURL()

React Native Linking.canOpenURL() with WhatsApp call

我正在尝试创建一个 link 以从我的 React 本机应用程序开始关于 whatsapp 的对话,但是方法 Linking.canOpenURL() 总是重新调整 false...

我的代码如下:

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

如果我尝试将其他一些 url 放在 tel:${celNumber} 它 returns 是真的,所以我认为 whatsapp url 和 canOpenURL() 存在一些问题,因为 whatsapp url 使用方法 Linking.openURL()...

我猜你正在使用 iOS? 然后你必须在你的 Info.plist 文件 LSApplicationQueriesSchemes.

中声明 URL 的方案 'whatsapp'

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