Reputation: 65
i'm having an issue trying to use the {Linking} package. I'd like to send a text message to an specific number, like in the following code:
import { Linking } from ‘react-native’;
WhatsApp = (text, phone) => {
Linking.openURL(`whatsapp://send?text=${text}&phone=${phone}`);
}
But it happens that the message gets written in the App's text field, but I still need to press the 'send' button in order to really deliver my message. Does anybody know how to fix it? (send the message without having to press the button?)
Upvotes: 0
Views: 61
Reputation: 1185
Try this way:
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');
}}
Please Note: send + in front of phone with country if opening in android
Upvotes: 1