Now that RN supports Linking cross-platform, I am wondering how to send an SMS with a preset message. Per the docs (https://facebook.github.io/react-native/docs/linking.html#content):
Try to open the given url with any of the installed apps.
You can use other URLs, like a location (e.g. "geo:37.484847,-122.148386"), a contact, or any other URL that can be opened with the installed apps.
My question is, what URI scheme do I follow to open an SMS with a predefined message? Is it cross-platform?
Thank you.
Have you considered and tried sms:number?body=yourMessage
?
You can read up on it in RFC 5724.
there's a difference between the platforms with the "body" divider
you can use the following code to make it work:
function openUrl(url: string): Promise<any> {
return Linking.openURL(url);
}
export function openSmsUrl(phone: string, body: string): Promise<any> {
return openUrl(`sms:${phone}${getSMSDivider()}body=${body}`);
}
function getSMSDivider(): string {
return Platform.OS === "ios" ? "&" : "?";
}
Pretty sure this is not React Native-specific, and is just about linking on Android. Take a look at: SMS URL on Android
OR you can simply do
url = `sms:${context.provider.state.driverPhoneNo}${Platform.OS === "ios" ? "&" : "?"}body=${""}`
Linking.openURL(url);
You can have a look at the react-packages react-native-communications(https://github.com/anarchicknight/react-native-communications). You can probably integrate the entire package or take parts of it