Respond to native SMS communication

Now that RN supports Linking cross-platform, I am wondering how to send SMS with a given message. In the docs ( https://facebook.imtqy.com/react-native/docs/linking.html#content ):

Try to open this URL with any of the installed applications. You can use other URLs, such as a location (for example, "geo: 37.484847, -122.148386"), a contact, or any other URL that can be opened with installed applications.

My question is, what URI scheme do I use to open SMS with a predefined message? Is it cross platform?

Thanks.

+10
source share
6 answers

Have you reviewed and tried sms:number?body=yourMessage ?

You can read it in RFC 5724 .

+9
source

there is a difference between 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" ? "&" : "?"; } 
+6
source

Pretty sure it's not React Native-specific, but just related to Android. Take a look at: Android SMS URL

+2
source

OR you can just do

 url = 'sms:${context.provider.state.driverPhoneNo}${Platform.OS === "ios" ? "&" : "?"}body=${""}' Linking.openURL(url); 
+1
source

You can take a look at the response-native communication response ( https://github.com/anarchicknight/react-native-communications ). Perhaps you can integrate the whole package or accept parts of it

0
source

If you want the user to choose from contacts, you can send my answer:

Respond to an iOS open message app with default text

0
source

Source: https://habr.com/ru/post/1245580/


All Articles