React native send a message to specific whatsapp Number

前端 未结 3 2138
野的像风
野的像风 2021-02-02 11:13

I\'m trying to send a text message to a WhatsApp contact from a react-native apps , i found that i can do it through Linking

Linking.openURL(\'whatsapp://send?t         


        
3条回答
  •  深忆病人
    2021-02-02 11:21

    share message to whatsapp to a specific predefined number independent to platform

        sendWhatsApp = () => {
        let msg = 'type something';
        let phoneWithCountryCode = 'xxxxxxxxxx';
    
        let mobile = Platform.OS == 'ios' ? phoneWithCountryCode : '+' + phoneWithCountryCode;
        if (mobile) {
          if (msg) {
            let url = 'whatsapp://send?text=' + msg + '&phone=' + mobile;
            Linking.openURL(url).then((data) => {
              console.log('WhatsApp Opened');
            }).catch(() => {
              alert('Make sure WhatsApp installed on your device');
            });
          } else {
            alert('Please insert message to send');
          }
        } else {
          alert('Please insert mobile no');
        }
      }
    

    Please Note: send + in front of phone with country if opening in android

提交回复
热议问题