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:
functionopenUrl(url: string): Promise<any> {
returnLinking.openURL(url);
}
exportfunctionopenSmsUrl(phone: string, body: string): Promise<any> {
returnopenUrl(`sms:${phone}${getSMSDivider()}body=${body}`);
}
functiongetSMSDivider(): string {
returnPlatform.OS === "ios" ? "&" : "?";
}
Solution 3:
I created a hook to send SMS messages:
import { useCallback } from'react'import { Linking, Platform } from'react-native'exportdefault () => {
const onSendSMSMessage = useCallback(async (phoneNumber, message) => {
const separator = Platform.OS === 'ios' ? '&' : '?'const url = `sms:${phoneNumber}${separator}body=${message}`awaitLinking.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"