首页 > 解决方案 > React Native 在深度链接时省略了井号键

问题描述

我正在尝试使用本机反应拨打电话号码。但是井号键不会添加到要呼叫的电话号码中。React Native 省略了数字中的“#”键。

  dialCall = (number,amount,pin) => {

    var phoneNumber = '';


    if (Platform.OS === 'android') {
      phoneNumber = `tel:*516*${number}*${amount}*${pin}#`
    }
    else {
      phoneNumber = `tel://*516*${number}*${amount}*${pin}#`
    }
  // console.log("credit transfer",phoneNumber)
    Linking.openURL(phoneNumber);
  };


render(){
    const { navigation} = this.props;
    return (
      <Background type='primary' style={styles.background}>


      <Card style={Styles.container}>

           <Text style={Styles.label}>Recipient</Text>

           <TextInput 
            value={this.state.transferRecipient}
            style={[Styles.input,flex=1]}
            placeholderTextColor='#666666'
            onChangeText={(text) => this.setState({transferRecipient:text})}
            keyboardType="phone-pad"
           />
           <Text style={Styles.label}>Amount</Text>

           <TextInput 
            value={this.state.transferAmount}
            style={[Styles.input,flex=1]}
            placeholderTextColor='#666666'
            onChangeText={(number) => this.setState({transferAmount:number})}
            keyboardType="phone-pad"
           />

           <View>
               <Text style={Styles.label}>Confirm Amount</Text>
               <TextInput 
                value={this.state.confirmTransferAmount}
                style={[Styles.input,flex=1]}
                placeholderTextColor='#666666'
                onChangeText={(number) => this.setState({confirmTransferAmount:number})}
                keyboardType="phone-pad"
               />
           </View>
           <View>
               <Text style={Styles.label}>Pin</Text>
               <TextInput 
               value={this.state.pin}
               style={[Styles.input,flex=1]}
               placeholderTextColor='#666666'
               onChangeText={(number) => this.setState({pin:number})}
               keyboardType="phone-pad"
               />
           </View>

         <Button
            title="Transfer Now"
            onPress= 

   {()=>this.dialCall(this.state.transferRecipient,this.state.transferAmount,this.state.pin)}
            style={Styles.buttonStyle}
            disabled={false}
            accessibilityLabel='transferCredit'
            textAccessibilityLabel='transferCredit'
       /> 

   </Card>

   </Background>

我想我在代码中遗漏了一些东西。本机反应会限制磅键被调用还是什么?我可以使用什么替代方式来调用反应本机中的号码

标签: reactjsreact-native

解决方案


我只需要更改 dialCall 函数中的一些变量

 dialCall = (number,amount,pin) => {

var phoneNumber = '';


 if (Platform.OS === 'android') {
   phoneNumber = `tel:*516*${number}*${amount}*${pin}+%23`
 }
 else {
  phoneNumber = `telprompt://*516*${number}*${amount}*${pin}+%23`
  }
// console.log("credit transfer",phoneNumber)
Linking.openURL(phoneNumber);
 };

推荐阅读