16

我正在尝试使用分机打开电话号码。链接仅使用电话号码

尝试了几个选项

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

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

拨号器只拨主号码,不包括分机

我可以编写本机代码并公开该方法,但那将是我的最后选择

4

2 回答 2

25

我知道已经晚了,但你可以试试这个组件:react-native-communications

它在 iOS 和 Android 上都运行良好。

您必须将其导入所需的文件中:

import Communications from 'react-native-communications';

然后根据需要使用它:

<TouchableOpacity onPress={() => Communications.phonecall(phoneNumbers[0].number, true)}>
于 2016-10-09T08:00:54.077 回答
19

这是我试过的,

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

和 JSX,

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

对我来说很好。您可以在这里找到更多关于链接的信息, https://facebook.github.io/react-native/docs/linking.html

于 2017-11-02T07:19:36.313 回答