Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/435.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/react-native/7.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 使用react&x27发布;s包链接以发送自动消息_Javascript_React Native_Messaging_Whatsapp - Fatal编程技术网

Javascript 使用react&x27发布;s包链接以发送自动消息

Javascript 使用react&x27发布;s包链接以发送自动消息,javascript,react-native,messaging,whatsapp,Javascript,React Native,Messaging,Whatsapp,我在尝试使用{Linking}包时遇到问题。我想向特定号码发送一条短信,如下代码所示: import { Linking } from ‘react-native’; WhatsApp = (text, phone) => { Linking.openURL(`whatsapp://send?text=${text}&phone=${phone}`); } 但是消息会被写入应用程序的文本字段中,但我仍然需要按下“发送”按钮才能真正传递消息。有人知道怎么修吗?(无需按下按钮即

我在尝试使用{Linking}包时遇到问题。我想向特定号码发送一条短信,如下代码所示:

import { Linking } from ‘react-native’;
 
WhatsApp = (text, phone) => {
 Linking.openURL(`whatsapp://send?text=${text}&phone=${phone}`);
}
但是消息会被写入应用程序的文本字段中,但我仍然需要按下“发送”按钮才能真正传递消息。有人知道怎么修吗?(无需按下按钮即可发送消息?

请尝试以下方法:

WhatsApp = () => {
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');
}}

请注意:如果在android中打开,请在手机前面发送+并注明国家/地区

非常感谢,我今天稍后会试用:)