React Native Linking SMS
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" ? "&" : "?";
}
Have you considered and tried sms:number?body=yourMessage
?
You can read up on it in RFC 5724.
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
}