React native — call phone number with extension

痴心易碎 提交于 2019-12-03 01:53:07

I know it is late, but you can try this component: react-native-communications.

It works well both on iOS and Android.

You have to import it in the file you need:

import Communications from 'react-native-communications';

and then use it as you need:

<TouchableOpacity onPress={() => Communications.phonecall(phoneNumbers[0].number, true)}>

This is what i tried,

callNumber = (url) =>{
   Linking.canOpenURL(url).then(supported => {
   if (!supported) {
    console.log('Can\'t handle url: ' + url);
   } else {
    return Linking.openURL(url);
   }
 }).catch(err => console.error('An error occurred', err));
}

And the JSX,

<Text onPress={()=> this.callNumber(`tel:+91${user.number}`)}
       style = {[styles.value,{marginLeft : 5,textDecorationLine :'underline'}]}>{`+91 ${user.number}`}</Text>
</View>

Works fine for me. You may find more on linking here, https://facebook.github.io/react-native/docs/linking.html

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!