【问题标题】:React Native Linking openURL : Use special characters like # and *React Native Linking openURL:使用特殊字符,如 # 和 *
【发布时间】:2021-09-30 18:26:36
【问题描述】:

我正在构建一个能够通过 USSD 代码触发移动支付的 React Native 应用程序(在非洲广泛使用)。

USSD 代码从任何手机的拨号器应用程序运行,如下所示:例如#144##1*1*4#

我的应用基本上应该将用户重定向到拨号器应用并用#144# 填写电话号码。

似乎无法使用 Linking.openURL 将特殊字符发送到 android dialer 应用...

这个 Linking.openURL(`tel:+221786756172`)

工作得很好,我有一个重定向并且电话号码已填满。

但这 Linking.openURL(`tel:#144#`)

不起作用,拨号器应用的字段仍然为空...

我试图转义特殊字符,没有成功。

你们能以任何方式帮助我吗,那是 UX 改进++

谢谢!!

【问题讨论】:

    标签: react-native react-native-linking


    【解决方案1】:

    先对 USSD 代码进行编码,然后再使用它。您可以使用以下功能:

    const phoneShare = (number) => {
        let phoneNumber = '';
        if (Platform.OS === 'android') { phoneNumber = `tel:${encodeURIComponent(number)}`; }
        else { phoneNumber = `telprompt:${number}`; }
        Linking.openURL("" + phoneNumber + "");
    };
    

    怎么用?

    <TouchableOpacity onPress={() => phoneShare('#144#')}>
        <Text>Press Me</Text>
    </TouchableOpacity>
    

    【讨论】:

    • 非常感谢!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-09-13
    • 1970-01-01
    • 2015-07-10
    • 1970-01-01
    • 1970-01-01
    • 2018-12-23
    • 2014-11-03
    相关资源
    最近更新 更多