React Native SMS模块

时间:2017-11-20 02:59:58

标签: react-native sms

我希望能够通过在ios或android上打开实际的短信应用程序本地发送来自本机应用程序的短信。有没有人知道在不使用twilio或Nexmo等API的情况下实现这一目标?

2 个答案:

答案 0 :(得分:0)

您可以使用此程序包react-native-sms-android 但它只适用于Android。

答案 1 :(得分:0)

您可以使用react-native-sms-x软件包。

您只需要将此项目添加到setting.gradlebuild.gradle文件中。然后下面的代码

import React, { Component } from 'react';
import {
  AppRegistry,
  StyleSheet,
  Text,
  View,
  TouchableOpacity,
  ToastAndroid
} from 'react-native';
import SendSMS from 'react-native-sms-x';

export default class RNSMS extends Component {
  sendSMSFunction() {
    SendSMS.send(123, "+95912345678", "Hey.., this is me!\nGood to see you. Have a nice day.",
      (msg)=>{
        ToastAndroid.show(msg, ToastAndroid.SHORT);
      }
    );
  }
  render() {
    return (
      <View style={styles.container}>        
        <TouchableOpacity style={styles.button} onPress={this.sendSMSFunction.bind(this)}>
          <Text>Send SMS</Text>
        </TouchableOpacity>
      </View>
    );
  }
}

const styles = StyleSheet.create({
  container: {
    flex: 1,
    justifyContent: 'center',
    alignItems: 'center',
    backgroundColor: '#F5FCFF',
  },  
  button: {
    padding: 10,
    borderWidth: .5,
    borderColor: '#bbb',
    margin: 10,
    alignItems: 'center',
    justifyContent: 'center'
  }
});

AppRegistry.registerComponent('RNSMS', () => RNSMS);

有关更多信息,请参见https://www.npmjs.com/package/react-native-sms-x