React native — call phone number with extension

蓝咒 提交于 2019-12-20 11:53:00

问题


I am trying to open phone number with extension. Linking works with just phone number

Tried with few options

Linking.openURL('tel:XXXXXXXXX,XXX');

Linking.openURL('tel:'+ encodeURIComponent('XXXXXXXXX,XXX'));

Dialer only dials primary number and doesnt include extension

I could write a native code and expose the method, but that would be my last option


回答1:


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)}>



回答2:


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



来源:https://stackoverflow.com/questions/38074623/react-native-call-phone-number-with-extension

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