React native 向特定的 whatsapp 号码发送消息
React native send a message to specific whatsapp Number
我正在尝试从反应本机应用程序向 WhatsApp 联系人发送短信,我发现我可以通过链接来做到这一点
Linking.openURL('whatsapp://send?text=hello');
上面的代码只打开什么应用程序,我需要打开一个特定号码的聊天是否有一个参数我必须像文本一样发送?!
您可以使用它向特定号码发送消息:
Linking.openURL('whatsapp://send?text=hello&phone=xxxxxxxxxxxxx')
您可以使用此方法将 whatsApp 消息直接发送到号码。
示例 link:https://wa.me/919234567812?text=%7B0%7D+Balaji+CTest
export const sendWhatsAppMessage = link => {
if (!isUndefined(link)) {
Linking.canOpenURL(link)
.then(supported => {
if (!supported) {
Alert.alert(
'Please install whats app to send direct message to students via whats
app'
);
} else {
return Linking.openURL(link);
}
})
.catch(err => console.error('An error occurred', err));
} else {
console.log('sendWhatsAppMessage -----> ', 'message link is undefined');
}
};
将消息分享到 whatsapp 到独立于平台的特定预定义号码
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');
}
}
请注意:如果在 android
开放,请在国家 phone 前发送 +
我正在尝试从反应本机应用程序向 WhatsApp 联系人发送短信,我发现我可以通过链接来做到这一点
Linking.openURL('whatsapp://send?text=hello');
上面的代码只打开什么应用程序,我需要打开一个特定号码的聊天是否有一个参数我必须像文本一样发送?!
您可以使用它向特定号码发送消息:
Linking.openURL('whatsapp://send?text=hello&phone=xxxxxxxxxxxxx')
您可以使用此方法将 whatsApp 消息直接发送到号码。
示例 link:https://wa.me/919234567812?text=%7B0%7D+Balaji+CTest
export const sendWhatsAppMessage = link => {
if (!isUndefined(link)) {
Linking.canOpenURL(link)
.then(supported => {
if (!supported) {
Alert.alert(
'Please install whats app to send direct message to students via whats
app'
);
} else {
return Linking.openURL(link);
}
})
.catch(err => console.error('An error occurred', err));
} else {
console.log('sendWhatsAppMessage -----> ', 'message link is undefined');
}
};
将消息分享到 whatsapp 到独立于平台的特定预定义号码
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');
}
}
请注意:如果在 android
开放,请在国家 phone 前发送 +