Skip to content Skip to sidebar Skip to footer

React Native Linking SMS

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#conten

Solution 1:

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

You can read up on it in RFC 5724.


Solution 2:

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" ? "&" : "?";
}

Solution 3:

I created a hook to send SMS messages:

import { useCallback } from 'react'
import { Linking, Platform } from 'react-native'

export default () => {
  const onSendSMSMessage = useCallback(async (phoneNumber, message) => {
    const separator = Platform.OS === 'ios' ? '&' : '?'
    const url = `sms:${phoneNumber}${separator}body=${message}`
    await Linking.openURL(url)
  }, [])

  return onSendSMSMessage
}

Solution 4:

Pretty sure this is not React Native-specific, and is just about linking on Android. Take a look at: SMS URL on Android


Solution 5:

OR you can simply do

url = `sms:${context.provider.state.driverPhoneNo}${Platform.OS === "ios" ? "&" : "?"}body=${""}`

Linking.openURL(url);

Post a Comment for "React Native Linking SMS"