react-native - 如何解决ReactNative中使用Linking调用iOS系统电话功能出现错误?

【字号: 日期:2023-12-26浏览:55作者:雯心

问题描述

在react中使用Linking组件调用iOS的电话功能:部分代码如下

_TelePhone(TelephoneNumber){ Platform.OS===’android’? NativeModules.phone.LawyerTelephone(TelephoneNumber):Linking.openURL(’tel:’+TelephoneNumber); } render() { return ( <Master navigator={this.props.navigator}><ScrollView showsHorizontalScrollIndicator={false} //去除水平滚动条 showsVerticalScrollIndicator={false} //去除垂直滚动条 pagingEnabled={true} //滚动优化 style={styles.padding10}> <View style={{}}> <Text style={styles.fontSize16}>案件详情:</Text> </View> <Text style={styles.lineHeight20}>大舅去二舅家找三舅说四舅被五舅骗去六舅家偷七舅放在八舅柜子里九舅借十舅发给十一舅工资的1000元。大舅去二舅家找三舅说四舅被五舅骗去六舅家偷七舅放在八舅柜子里九舅借十舅发给十一舅工资的1000元。大舅去二舅家找三舅说四舅被五舅骗去六舅家偷七舅放在八舅柜子里九舅借十舅发给十一舅工资的1000元。</Text></ScrollView><View style={styles.btnNext}> <TouchableOpacity onPress={()=>this._TelePhone(this.props.TEL)}> <Text style={styles.btnText}>开始服务</Text> </TouchableOpacity></View> </Master> ) }点击按钮时不能达到跳转到电话应用的效果,后台提示错误代码如下:

Possible Unhandled Promise Rejection (id: 0):Unable to open URL: telprompt:18217049979Error: Unable to open URL: telprompt:18217049979

求大神指点,谢谢!

问题解答

回答1:

问题已经解决了,原来是模拟器的缘故,到真机上测试全部的OK

回答2:

建议你catch一下,不然崩溃就不好了

Linking.openURL(’tel:’+TelephoneNumber).catch(e=>console.war(e))

相关文章: