How to make phone call in React Native?
I want to call to the value of Text component when I press it. But, actually, I haven't enough knowledge for that.
Can you, please, tell me, which library or component should I use?
If you look at the source code for react-native-phone-call
, it's ultimately just a wrapper for:
import {Linking} from 'react-native'
Linking.openURL(`tel:${phoneNumber}`)
You can use this method to call numbers in android and ios, place this method in a utils file and use the method wherever you want. cheers
import { Linking, Alert, Platform } from 'react-native';
export const callNumber = phone => {
console.log('callNumber ----> ', phone);
let phoneNumber = phone;
if (Platform.OS !== 'android') {
phoneNumber = `telprompt:${phone}`;
}
else {
phoneNumber = `tel:${phone}`;
}
Linking.canOpenURL(phoneNumber)
.then(supported => {
if (!supported) {
Alert.alert('Phone number is not available');
} else {
return Linking.openURL(phoneNumber);
}
})
.catch(err => console.log(err));
};
**Update ( Andrey Patseiko's comment) **
Don't forget added to Info.plist
->
<key>LSApplicationQueriesSchemes</key>
<array>
<string>tel</string>
<string>telprompt</string>
</array>