第一種方法:
Linking:調用系統的電話、短信、郵件、瀏覽器等功能
Linking.canOpenURL(this.props.url).then(supported => { if (!supported) { console.log('Can\'t handle url: ' + this.props.url); } else { return Linking.openURL(this.props.url); } }).catch(err => console.error('An error occurred', err)); 調用系統的電話功能 tel:10086 Android:直接到轉到系統撥號頁面,沒有問題 iOS:彈出一個alert,顯示電話號碼,一個取消按鈕,一個確定按鈕 點擊確定撥打電話,沒有問題 點擊取消不打電話,程序崩潰提示錯誤(我看不懂),有問題,暫未解決 NO2.調用系統的短信功能 smsto:10086 Android:跳轉發短信界面,沒有問題 iOS:無法跳轉到發短信界面,一直提示沒有權限 然而打電話、發短信、Safari瀏覽器並不需要權限,有問題,暫未解決 NO3.調用系統的郵件功能 mailto:xxxxxxxxx@qq.com Android:沒有問題 iOS:沒有問題 NO4.調用系統的瀏覽器功能 http://www.baidu.com Android:沒有問題 iOS:沒有問題
第二種方法:
三方組件:react-native-communications
地址:https://github.com/anarchicknight/react-native-communications
網址里面的 README.md 寫的非常的清楚,而且還有例子可供參考
npm install react-native-communications import Communications from 'react-native-communications'; render() { return ( <View style={styles.container}> <TouchableOpacity style={{height:40,marginTop:40}} onPress={()=>{ Communications.phonecall('10086', false); }}> <Text>調用系統打電話功能</Text> </TouchableOpacity><TouchableOpacity style={{height:40,marginTop:40}} onPress={()=>{ Communications.text('10086','要發送的內容'); Communications.textWithoutEncoding('10086','要發送的內容encoding');//這種方法需要將內容encoding }}> <Text>調用系統發短信功能</Text> </TouchableOpacity><TouchableOpacity style={{height:40,marginTop:40}} onPress={()=>{ Communications.email(['emailAddress1', 'emailAddress2'],null,null,'My Subject','My body text') }}> <Text>調用系統發郵件功能</Text> </TouchableOpacity><TouchableOpacity style={{height:40,marginTop:40}} onPress={()=>{ Communications.web('https://github.com/facebook/react-native') }}> <Text>調用系統打開網頁功能</Text> </TouchableOpacity> </View> ); }