使用 react 的软件包时出现问题 链接以发送自动消息



我在尝试使用{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中打开,请在带有国家/地区的手机前发送+

最新更新