Javascript 使用react&x27发布;s包链接以发送自动消息
我在尝试使用{Linking}包时遇到问题。我想向特定号码发送一条短信,如下代码所示: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}`); } 但是消息会被写入应用程序的文本字段中,但我仍然需要按下“发送”按钮才能真正传递消息。有人知道怎么修吗?(无需按下按钮即
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中打开,请在手机前面发送+并注明国家/地区非常感谢,我今天稍后会试用:)