代码之家  ›  专栏  ›  技术社区  ›  Marcelo Tardelli Magalhães

反应本机链接。带有WhatsApp调用的canOpenURL()

  •  8
  • Marcelo Tardelli Magalhães  · 技术社区  · 6 年前

    我试图创建一个链接,从我的react原生应用程序开始whatsapp上的对话,但方法链接。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} 它返回true,因此我认为whatsapp url和canOpenURL()存在一些问题,因为whatsapp url与方法链接一起工作。openURL()。。。

    1 回复  |  直到 6 年前
        1
  •  2
  •   SinunHenkka    6 年前

    我怀疑你在使用iOS? 然后,您必须在信息中声明URL方案“whatsapp”。plist文件lsapplicationqueryschemes。

    iOS9: canOpenURL returning false for WhatApp's url scheme

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