简体   繁体   English

React Native中用于处理电子邮件和电话号码链接的任何组件/ API

[英]Any component/API in React Native to handle Email and Phone Number links

LinkingIOS says the following: LinkingIOS说如下:
* The iOS simulator does not support the mailto: and tel: schemas * because the Mail and Phone apps are not installed - you will need to test * them on a device. * iOS模拟器不支持mailto:tel: schemas *,因为未安装Mail和Phone应用程序 - 您需要在设备上测试*它们。

What can I use in my React Native app to link to the native Mail app when an email address is clicked on? 当点击电子邮件地址时,我可以在我的React Native应用程序中使用什么链接到本机Mail应用程序? And similarly, how do I give the option to call or text-message when a telephone number is clicked on? 同样,如果点击电话号码,如何选择拨打电话或短信?

You can use the LinkingIOS.openURL(url). 您可以使用LinkingIOS.openURL(url)。 It will work perfect on actual iPhone. 它将在真正的iPhone上完美运行。 You cannot test it on Simulator because those apps are not available on simulator. 您无法在模拟器上测试它,因为这些应用程序在模拟器上不可用。 So, use mailto: for email, tel: for call & sms: for sending SMS. 因此,使用mailto:用于电子邮件,tel:用于呼叫和短信:用于发送短信。

I would also recommend you doing feature detection using LinkingIOS.canOpenURL because, iPad will also not support the call and sms features. 我还建议你使用LinkingIOS.canOpenURL进行功能检测,因为iPad也不支持通话和短信功能。 So its always good idea to check the support for the url scheme before using it. 因此,在使用url方案之前检查对url方案的支持始终是个好主意。

react-native-communications very nice react native npm module. react-native-communications非常好反应本机npm模块。 which supports phone call, sms, email, and urls. 它支持电话,短信,电子邮件和网址。

Open a web address, easily call, email, text, iMessage (iOS only) someone in React Native 在React Native中打开一个Web地址,轻松调用,发送电子邮件,发送文本,iMessage(仅限iOS)

<View style={styles.container}>
        <TouchableOpacity onPress={() => Communications.phonecall('0123456789', true)}>
          <View style={styles.holder}>
            <Text style={styles.text}>Make phonecall</Text>
          </View>
        </TouchableOpacity>
        <TouchableOpacity onPress={() => Communications.email(['emailAddress1', 'emailAddress2'],null,null,'My Subject','My body text')}>
          <View style={styles.holder}>
            <Text style={styles.text}>Send an email</Text>
          </View>
        </TouchableOpacity>
        <TouchableOpacity onPress={() => Communications.text('0123456789')}>
          <View style={styles.holder}>
            <Text style={styles.text}>Send a text/iMessage</Text>
          </View>
        </TouchableOpacity>
        <TouchableOpacity onPress={() => Communications.web('https://github.com/facebook/react-native')}>
          <View style={styles.holder}>
            <Text style={styles.text}>Open react-native repo on Github</Text>
          </View>
        </TouchableOpacity>
      </View>

I found a third lib which called react-native-autolink https://github.com/joshswan/react-native-autolink 我找到了第三个名为react-native-autolink lib, https://github.com/joshswan/react-native-autolink

Hope this can help to you 希望这对你有所帮助

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM