【问题标题】:React Native Send sms within the appReact Native 在应用内发送短信
【发布时间】:2018-12-06 17:29:39
【问题描述】:

我想在不打开默认消息应用程序的情况下向多个号码发送短信。 我尝试使用react-native-sms-x,但它没有得到维护,我的项目只是停留在编译。 我也使用了react-native-sms,但它打开了默认的消息应用程序,其中填充了一个用户号和消息正文,并且也必须单击它的发送按钮。

【问题讨论】:

  • 您对此有答案吗?我也在找同样的功能,谢谢!

标签: android ios react-native sms


【解决方案1】:

在 React 应用中经过大量研究和试验后... 我发现 this 库工作正常,并达到了发送消息的目标,而无需进入默认消息环境。

var phoneNumbers = {
        "addressList": ["+911212121212", "+911212121212"]
      };
    var message = "This is automated test message"
    SmsAndroid.autoSend(
        phoneNumbers,
        message,
        (fail) => {
            console.log('Failed with this error: ' + fail);
        },
        (success) => {
            console.log('SMS sent successfully');
        },
    );

希望对你有帮助。别忘了点赞

【讨论】:

  • 这是我工作过的最好的图书馆,只是想问问你的经验对你有帮助吗?
【解决方案2】:
import { Linking,Platform  } from "react-native";

    const url = (Platform.OS === 'android')
    ? 'sms:919999999999?body=your message'
    : 'sms:919999999999'
    Linking.canOpenURL(url).then(supported => {
      if (!supported) {
        console.log('Unsupported url: ' + url)
      } else {
        return Linking.openURL(url)
      }
    }).catch(err => console.error('An error occurred', err))

【讨论】:

  • 我认为它会打开默认的短信应用程序,里面装满了给定的短信号码和消息。
【解决方案3】:

从现在开始,我只为 Android 使用 react-native-sms-android 这是我向多个用户发送短信的代码:

import Asms from "react-native-sms-android";
type Props = {};
export default class App extends Component<Props> {
  constructor(Props) {
        super(Props);
        this.state = { FileNumbers: ['687867867867','8575774433'], Message: 
          "gjjgjgj" };
         }

  sendingSms = (Receivers, Messagex) => {
           try {
                Receivers.map(
                async Numbers =>
                  await Asms.sms(Numbers, Messagex, "sendDirect", (err,message) 
                    => {
                    if (err) {
                      console.log(err);
                    } else {
                      console.log(message);
                    }
                  })
              );
            } catch (e) {
              alert("" + e);
            }
          };

      render() {
        return (
          <View style={styles.container}>
            <TextInput
              style={{
                height: 40,
                borderColor: "gray",
                borderWidth: 1,
                width: "90%"
              }}
              onChangeText={Message => this.setState({ Message })}
              value={this.state.Message}
            />
            <Button
              title="SEND"
              onPress={() =>
                this.sendingSms(this.state.FileNumbers, this.state.Message)
              }
            />

          </View>
        );
      }
    }

【讨论】:

    猜你喜欢
    • 2019-09-19
    • 2019-06-02
    • 2012-05-04
    • 2011-04-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-07-03
    相关资源
    最近更新 更多